Railsチュートリアル(1~3章)をやった時のエラー解消
Railsチュートリアルを1度コピペで行いました。
2週目はちゃんと入力してやってみようかと思います。
タイポが多いので、エラーがわんさか ワーワー ヽ(゚∀゚)ノ ワーワー ヽ(゚∀゚)ノ ワーワー
今回やるバージョンは4.0です。
まずは1章から、、、って言ってもほとんどなかったですが。
$ git push -u origin master Username for 'https://github.com': himajin315 Password for 'https://himajin315@github.com': remote: Repository not found. fatal: repository 'https://github.com/himain315/first_app.git/' not found $ git remote add origin https://github.com/himajin315/first_app.git fatal: remote origin already exists.
ユーザ名をミスった!!
renameもあるけど消そう。
$ git remote remove origin $ git remote add origin git@github.com:himajin315/first_app.git
次に2章です。
$ bundle install --without production Fetching gem metadata from https://rubygems.org/.......... Fetching additional metadata from https://rubygems.org/.. Resolving dependencies... Bundler could not find compatible versions for gem "railties": In snapshot (Gemfile.lock): railties (4.0.4) In Gemfile: rails (= 4.0.2) ruby depends on railties (= 4.0.2) ruby Running `bundle update` will rebuild your snapshot from scratch, using only the gems in your Gemfile, which may resolve the conflict.
bundle update をやれということですね。
$ bundle update Fetching gem metadata from https://rubygems.org/.......... Fetching additional metadata from https://rubygems.org/.. Resolving dependencies... Using rake (10.3.1) Using i18n (0.6.9) Using minitest (4.7.5) Using multi_json (1.9.2) Using thread_safe (0.3.3) Using tzinfo (0.3.39) Using activesupport (4.0.2) Using builder (3.1.4) Using erubis (2.7.0) Using rack (1.5.2) Using rack-test (0.6.2) Using actionpack (4.0.2) Using mime-types (1.25.1) Using polyglot (0.3.4) Using treetop (1.4.15) Using mail (2.5.4) Using actionmailer (4.0.2) Using activemodel (4.0.2) Using activerecord-deprecated_finders (1.0.3) Using arel (4.0.2) Using activerecord (4.0.2) Using bundler (1.5.3) Using coffee-script-source (1.7.0) Using execjs (2.0.2) Using coffee-script (2.2.0) Using thor (0.19.1) Using railties (4.0.2) Using coffee-rails (4.0.1) Using hike (1.2.3) Using jbuilder (1.0.2) Using jquery-rails (3.0.4) Using json (1.8.1) Using tilt (1.4.1) Using sprockets (2.12.1) Using sprockets-rails (2.0.1) Using rails (4.0.2) Using rdoc (3.12.2) Using sass (3.3.5) Using sass-rails (4.0.1) Using sdoc (0.3.20) Using sqlite3 (1.3.8) Using turbolinks (1.1.1) Using uglifier (2.1.1) Your bundle is updated! Gems in the group production were not installed.
次は3章です。
$ rails generate rspec::install /Users/y.oshiro/daigaku/rails_projects/sample_app/config/initializers/secret_token.rb:22:in `secure_token': undefined local variable or method `tokne_file' for main:Object (NameError) (省略)
secure_token の tokne_file は定義されてない。(いつものやつ)
【Before】 File.write(tokne_file,token) 【After】 File.write(token_file,token)
$ git push -u origin master Username for 'https://github.com': himajin315 Password for 'https://himajin315@github.com': To https://github.com/himajin315/sample_app.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/himajin315/sample_app.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
あー。すでにsample_appはあったんだった。
前に作った sample_app -> sample_app2 に変更。
新しく sample_app レポジトリを作成してからpushしましょう。
$ git push -u origin master Counting objects: 64, done. Delta compression using up to 4 threads. Compressing objects: 100% (53/53), done. Writing objects: 100% (64/64), 14.64 KiB, done. Total 64 (delta 4), reused 0 (delta 0) To https://github.com/himajin315/sample_app.git * [new branch] master -> master Branch master set up to track remote branch master from origin.
$ heroku create ! You've reached the limit of 5 apps for unverified accounts. ! Add a credit card to verify your account.
herokuで無料で使えるのは5個までらしいです。
なので、いらないのは消しましょう。
$ heroku create Creating polar-plains-6540... done, stack is cedar http://polar-plains-6540.herokuapp.com/ | git@heroku.com:polar-plains-6540.git Git remote heroku added
$ git push heroku master The authenticity of host 'heroku.com (50.19.85.156)' can't be established. RSA key fingerprint is 8b:48:5e:67:0e:c9:16:47:32:f2:87:0c:1f:c8:60:ad. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'heroku.com,50.19.85.156' (RSA) to the list of known hosts. Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
あー。heroku の SSH Keysを登録してなかったなー。
https://dashboard.heroku.com/account で SSH Keys を登録しましょう。
$ git push heroku master ・・・ http://calm-mountain-4856.herokuapp.com/ deployed to Heroku To git@heroku.com:calm-mountain-4856.git * [new branch] master -> master
$ bundle exec rspec spec/requests/static_pages_spec.rb /Users/y.oshiro/daigaku/rails_projects/sample_app/spec/requests/static_pages_spec.rb:1:in `require': cannot load such file -- spec_helper (LoadError) ・・・
あれ?spec_helperがない!!!
過去のコマンドをよく見ると「rails generate rspec::install」ってやってた(*ノω・*)テヘ
$ rails generate rspec:install identical .rspec exist spec identical spec/spec_helper.rb
これで完璧。
$ bundle exec rspec spec/requests/static_pages_spec.rb F Failures: 1) Home page shold have the content 'Sample App' Failure/Error: visit '/static_page/home' ActionController::RoutingError: No route matches [GET] "/static_page/home" # ./spec/requests/static_pages_spec.rb:5:in `block (2 levels) in <top (required)>' Finished in 0.00707 seconds 1 example, 1 failure Failed examples: rspec ./spec/requests/static_pages_spec.rb:4 # Home page shold have the content 'Sample App'
あれ・・・。
チュートリアルのエラーと違う。
【Before】 visit '/static_page/home' 【After】 visit '/static_pages/home'
「s」を忘れてました。
第3章ではタイポが多くて疲れました。。。
今日はこのへんで (*´∀`)ノシ