【发布时间】:2014-09-04 06:10:51
【问题描述】:
在我的 Rails 网站上,当用户通过表单添加产品时,我需要将他们带到产品页面并显示一个可以在我的 JavaScript 中检测到的 flash(flash 将为空白);我正在使用我在 application.html.erb 中设置的自定义闪存。我不确定是否需要为此使用重定向或渲染。这是我的创建操作(不起作用):
def create
@product = Product.new(product_params)
@product.set_user!(current_user)
respond_to do |format|
if @product.save
if !current_user.braintree_customer_id?
flash.now[:addmethod] = ""
format.html {render :action => "show"}
else
format.html {render :action => "show"}
end
else
flash.now[:alert] = "Woops, looks like something went wrong."
format.html {render :action => "create"}
end
end
end
那么我需要使用什么?渲染还是重定向?
【问题讨论】:
-
你应该
redirect到show行动。 -
@RAJ...
new我相信? -
@nithin 让我重新措辞一下,他应该在创建操作中创建记录后重定向控件以显示操作。
-
@RAJ... 对。我正在担任
else的一部分。
标签: javascript ruby-on-rails flash