モデルを保存した後、モデルのインデックスビューにリダイレクトしたい。
def create
@test = Test.new(params[:test])
respond_to do |format|
if @test.save
format.html { redirect_to @test, notice: 'test was successfully created.' }
else
format.html { render action: "new" }
end
end
end
私はもう試した
format.html { render action: "index", notice: 'Test was successfully created.' }
しかし、/ app / views / tests/index.html.erbで次のエラーが発生します-
undefined method `each' for nil:NilClass
何が悪いのか分かりますか?