質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

2484閲覧

rails generate controller のコマンドを誤って2回してしまった場合の対処方法

takuo5

総合スコア48

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2019/10/10 06:20

前提・実現したいこと

Railsチュートリアル学習中のものです。現在14.2.5のfollowボタンの部分を進めていてその最後にrails testコマンドを打ち込むはずが誤ってrails generate controller Relationshipsコマンドを打ち込んでしまいました。
リンク内容
その後はconflictが下記2件の箇所で起こりました。

conflict app/controllers/relationships_controller.rb
Overwrite /home/ec2-user/environment/sample_app/app/controllers/relationships_controller.rb? (enter "h" for help) [Ynaqdhm]

conflict test/controllers/relationships_controller_test.rb
Overwrite /home/ec2-user/environment/sample_app/test/controllers/relationships_controller_test.rb? (enter "h" for help) [Ynaqdhm]

この際にEnterをおして抜けてしまったのですが、その後rails testを打ち込むとエラーが起きました。
この場合はどのように対処すればよろしいでしょうか?

発生している問題・エラーメッセージ

ERROR["test_should_unfollow_a_user_with_Ajax", FollowingTest, 2.092911899000228] test_should_unfollow_a_user_with_Ajax#FollowingTest (2.09s) ActionView::Template::Error: ActionView::Template::Error: undefined method `id' for nil:NilClass app/views/users/_follow.html.erb:2:in `block in _app_views_users__follow_html_erb___1827588714319501049_64435160' app/views/users/_follow.html.erb:1:in `_app_views_users__follow_html_erb___1827588714319501049_64435160' app/views/relationships/destroy.js.erb:1:in `_app_views_relationships_destroy_js_erb___2200646867196533539_64421200' test/integration/following_test.rb:53:in `block (2 levels) in <class:FollowingTest>' test/integration/following_test.rb:52:in `block in <class:FollowingTest>' ERROR["test_should_follow_a_user_with_Ajax", FollowingTest, 2.1544998910003414] test_should_follow_a_user_with_Ajax#FollowingTest (2.15s) ActionView::Template::Error: ActionView::Template::Error: undefined method `id' for nil:NilClass app/views/users/_unfollow.html.erb:1:in `_app_views_users__unfollow_html_erb___807541820124113879_67512860' app/views/relationships/create.js.erb:1:in `_app_views_relationships_create_js_erb__4011867530934198434_67498560' test/integration/following_test.rb:37:in `block (2 levels) in <class:FollowingTest>' test/integration/following_test.rb:36:in `block in <class:FollowingTest>' ERROR["test_should_unfollow_a_user_the_standard_way", FollowingTest, 2.1841038560000925] test_should_unfollow_a_user_the_standard_way#FollowingTest (2.18s) ActionController::UnknownFormat: ActionController::UnknownFormat: RelationshipsController#destroy is missing a template for this request format and variant. request.formats: ["text/html"] request.variant: [] test/integration/following_test.rb:45:in `block (2 levels) in <class:FollowingTest>' test/integration/following_test.rb:44:in `block in <class:FollowingTest>' ERROR["test_should_follow_a_user_the_standard_way", FollowingTest, 2.2125239619999775] test_should_follow_a_user_the_standard_way#FollowingTest (2.21s) ActionController::UnknownFormat: ActionController::UnknownFormat: RelationshipsController#create is missing a template for this request format and variant. request.formats: ["text/html"] request.variant: [] test/integration/following_test.rb:31:in `block (2 levels) in <class:FollowingTest>' test/integration/following_test.rb:30:in `block in <class:FollowingTest>' 62/62: [=======================================================================================================================================] 100% Time: 00:00:02, Time: 00:00:02 Finished in 2.54242s 62 tests, 297 assertions, 0 failures, 4 errors, 0 skips

該当のソースコード

ソースコード

試したこと

ここに問題に対して試したことを記載してください。

補足情報(FW/ツールのバージョンなど)

AWS Cloud9

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

正常な状態のコミットがあるのであればそこまで戻る。
無いのであればまたファイルを編集し直す。
エディターに巻き戻し機能があってそれが使えるのであればそれを使ってもいいです。
とにかく上書きされたファイルを以前の状態に戻すしか無いですね。

投稿2019/10/10 06:24

Mugheart

総合スコア2349

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

takuo5

2019/10/10 12:38

ご回答頂きありがとうございます。 要するに、rails generate controller Relationshipsで作成されるファイルだけ編集して元の状態に戻すことができたら問題はないとのことでしょうか? それでしたら、relationships_controller.rbとrelationships_controller_test.rbだけもとに戻せば解決できると思うのですが、 心配なのがrails generate controller Relationshipsのコマンドによってその他データベース等になにか変更を与えたりしてないかということなのですが、この心配はなさそうですか?
Mugheart

2019/10/10 12:53

ファイルが自動生成されただけなのでDBに影響はありません。
takuo5

2019/10/10 13:07

ありがとうございます。 relationships_controller.rbとrelationships_controller_test.rb修正してrails testをして問題なければ先に勧めます。 少し大げさな質問だったかもしれませんが、ご丁寧に対応していただきましてありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問