开发者

Rails render if @transaction.save fails

I've been struggling wi开发者_运维问答th this for a while now...

I have a more complex form (saves one transaction and two transaction_data at the same time).

I got it to save all right, however I am struggling with the handling of errors. If I use the following in "create" - in case of an error - it doesn't hold any of the values I've had on the same page before the submit and basically ends in rails error.

if @transac.save
   ...
else
   ...
   format.html { render :action => 'buy' }
end

Also in "buy" (in the controller) before I submit the form I've had stuff like:

@transac = Transac.new
2.times { @transac.transaction_datas.build }
@my_collection = current_user.items.all

The problem is that in case of an error Rails doesn't run the Controller action "buy", but only its view. How can I handle this? I need @my_collection to display the list of radio-button elements the user would pick from in case of an error?!


Are you sure transaction (or even get??) isn't a reserved word?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜