前提・実現したいこと
「create」アクションで保存したデータを「show」アクションで表示したいです。
発生している問題・エラーメッセージ
「new」アクションで「form_for」を活用し「period」と「step」という二つのモデルにデータを作成し「create」アクションでデータを保存しました。
その後、同controller内の「show」アクションにredirectしたいのですが、エラーが発生します。
エラーメッセージ
ActionController::UrlGenerationError in TopController#create
No route matches {:action=>"show", :controller=>"top"}
Extracted source (around line #15):
13 @period = Period.create(period_params)
14 @step = Step.create(step_params)
15 redirect_to :action => "show" #ここが赤く表示されています
16
17 end
18 def show
該当のソースコード
ソースコード 【/app/controllers/top_controller.rb】 class TopController < ApplicationController def index end def new @period = Period.new @step = Step.new end def create @period = Period.create(period_params) @step = Step.create(step_params) redirect_to :action => "show" end def show @period = Period.find(params[:id]) @step = Step.find(params[:id]) end private def period_params params.require(:period).permit(:start_date) end def step_params params.require(:period).require(:step).permit(:stepname, :stepcount).merge(period_id: params[:period_id]) end end
ルート root GET / top#index top_index GET /top(.:format) top#index POST /top(.:format) top#create new_top GET /top/new(.:format) top#new edit_top GET /top/:id/edit(.:format) top#edit top GET /top/:id(.:format) top#show PATCH /top/:id(.:format) top#update PUT /top/:id(.:format) top#update DELETE /top/:id(.:format) top#destroy
試したこと
色々ググりましたが、どこに原因があるのかわからず質問をさせて頂きました。
まだRubyを初めて1ヶ月の初心者でして、とても初歩的な質問かもしれません。
恐縮ですが、何卒アドバイスをご教示いただけますと幸いです。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/11 06:11
2018/05/11 06:15
2018/05/11 09:19