engine model(エンジン)
とbid_price model(入札価格)
があります。
engine
に対してbid_price
を入れることから、engine conrtoller#showのview
中にbid_priceのform
を入れています。つまりBidPrice.new
はengine controller
で行なっており、bid_price controller
にはcreateアクション
しかありません。
ruby
1class EnginesController < ApplicationController 2 def show 3 @engine = Engine.find(params[:id]) 4 @tender_rule = @engine.seller.tender_rule 5 @bid_price = BidPrice.new 6 end 7end 8 9class BidPricesController < ApplicationController 10 11 def create 12 bidded_engine = Engine.find(params[:engine_id]) 13 @bid_price = BidPrice.new(bid_price_params) 14 @bid_price.user = current_user 15 @bid_price.engine = bidded_engine 16 if @bid_price.valid? 17 @bif_price.save! 18 flash.notice = "Your Price has been submitted!" 19 redirect_to tender_engine_path(bidded_engine.tender, bidded_engine) 20 else 21 @engine = bidded_engine 22 @tender_rule = @engine.seller.tender_rule 23 @bid_price_errors = @bid_price.errors 24 redirect_to tender_engine_path(bidded_engine.tender, bidded_engine) 25 end 26 end 27end 28
起きている問題
bid priceをcreateし、validationでエラーが出た際に、エラーメッセージをengine_controller#show
で表示したい考えております。
@bid_price.errors
でエラーメッセージが保持されていることは確認しているのですが、
engine_controller#show
にredirectされると保持されていたメッセージは消えてしまいます。
以下のように買いてみましたが、どうやっても@bid_prieが保持していたerrorメッセージが受け渡せず、解決策をご教示頂けますと助かります。
ruby
1class EnginesController < ApplicationController 2 def show 3 @engine = Engine.find(params[:id]) 4 @tender_rule = @engine.seller.tender_rule 5 if @bid_price&.errors.present? 6 @bid_price_errors = @bid_price.errors 7 end 8 @bid_price = BidPrice.new 9 end 10end 11
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/12 01:06
2019/03/12 03:17
2019/03/12 04:57