respond_with redirect with notice flash message not working
我正在使用rails 3.0.7。 在控制器中我有:
def create @subscription = Subscription\ .new_from_nested_attributes_parameters(params[:subscription]) if @subscription.save flash[:notice] = 'The Subscription was successfully created.' end respond_with @subscription end
并在视图中:
尽管正确保存了对象,但不打印任何内容。
你对我该如何解决这个问题有所了解吗?
我发现了这个问题。
flash [:notice] =“….”正在处理创建操作,重定向到show动作。
我忘记的是我的’节目’包含重定向编辑。
我通过实现这样的show动作来解决这个问题:
def show redirect_to edit_subscription_path(@subscription),flash end
从Rails 3.1开始,这应该通过以下方式完成:
def show flash.keep redirect_to edit_subscription_path(@subscription) end
在Rails 3.2中,以下内容将起作用并且似乎可以保持闪存不变:
respond_with @subscription, :location => edit_subscription_path(@subscription)
您可以跳过显示页面:
代替:
respond_with @subscription
放:
respond_with @subscription, edit_subscription_path(@subscription)