respond_with redirect with notice flash message not working

前端 未结 3 1586
栀梦
栀梦 2021-01-14 09:21

I am using rails 3.0.7. In the controller I have:

  def create
    @subscription = Subscription\\
      .new_from_nested_attributes_parameters(params[:subscr         


        
相关标签:
3条回答
  • 2021-01-14 09:34

    In Rails 3.2, the following will work and appears to keep the flash intact:

    respond_with @subscription, :location => edit_subscription_path(@subscription)
    
    0 讨论(0)
  • 2021-01-14 09:42

    I discovered the problem.

    flash[:notice]="...." is properly working on the create action, redirecting to the show action.

    What I forgot was that my 'show' consists on a redirect to edit.

    I fixed this by implementing the show action like this:

    def show
      redirect_to edit_subscription_path(@subscription),flash
    end
    

    From Rails 3.1 on, this should be accomplished with:

    def show
      flash.keep
      redirect_to edit_subscription_path(@subscription)
    end
    
    0 讨论(0)
  • 2021-01-14 09:46

    You can skip the show page:

    Instead of:

    respond_with @subscription
    

    Put:

    respond_with @subscription, edit_subscription_path(@subscription)
    
    0 讨论(0)
提交回复
热议问题