[英]Changing the default routing upon validation error (rails)
我的line_item模型具有唯一性驗證:
validates :course_id, :uniqueness => {:scope => :cart_id}
如果我有意創建一個未能通過驗證的line_item,Rails會自動將我帶到/ line_items。 如何更改此默認路由?
驗證失敗時將發生的情況將由控制器的create方法確定。 在那兒您需要一些類似的東西
def create
if LineItem.create(params)
render :action => 'index'
else
render :action => 'edit'
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.