app/model/items.rb
def bulk_insert validate: true if validate unless valid? return false end end ...
app/controller/items_controller.rb
def save if @item.try!(:bulk_insert) redirect_to action: :xx, id: @item.id else flash[:item_params] = update_params redirect_to action: :new, itemid: update_params["item_id"] end end def new @item = @xx.find_by(xx_id: xx_params) end
app/views/items/new.slim
- if @item.errors.any? binding.pry
上記のようなコードがあって
unless valid? return false end
に引っかかってfalseが返った時のerrors.messagesの内容を
redirectされたnew.slim上で拾いたいですが、方法がよくわかりませんでした。
app/model/items.rb上でbinding.pryしてみるとerrors.messagesの値は確認できましたが、
redirect_to action: :new, itemid: update_params["item_id"]
されてerrors.messagesを拾うにはどう風に実装した方がよろしいでしょうか。
何か参考できるのありましたらご教示ください。
よろしくお願いします!
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。