0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

undefined method `question_url' for #<QuestionsController:0x0000000000feb0>

Posted at

redirect_to @インスタンス変数 でエラーがでる

スクリーンショット 2023-06-15 20.57.41.png

@インスタンスってrailsのバージョンによって使えないんだっけ?とか考えたり
コードは正しいように見えるが、、

questions_controller.rb
class QuestionsController < ApplicationController
.
.
.
    def create
        # 初期化
        @question = Question.new(question_params)
        # DBに保存
        @question.save
        # リダイレクト
        redirect_to @question 
        # redirect_to action: :show
    end
.
.
.

関連するソースを見ていったところ

routes.rb
resource :users

スペルミスでsが抜けていた、、

routes.rb
resources :users

修正したら無事動きました。
スペル間違いどうにかしたい、、

同じエラー出た人は関係してるソース見返すと間違いが見つかるかもしれません。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?