开发者

Rails 2.3.5: flash[:notice] disappears after redirect_to call

开发者 https://www.devze.com 2022-12-31 04:10 出处:网络
Here I\'ve got two controller methods: def invite if request.post? begin email = AccountMailer.create_invite(@user,url)

Here I've got two controller methods:

  def invite
    if request.post?
      begin 
        email = AccountMailer.create_invite(@user,url)
        AccountMailer.deliver(email)
        flash[:notice] = "Invitation email sent to #{@user.email}"
      rescue
        #mail delivery failed
        flash[:error] = "Failed to deliver invitation"
      end

      redirect_to :action => :show, :id => @user.id
    end
  end

and

  def show
    @title = "User #{@user.full_name}"
  end

The problem is, when I send an invitation, and get redirected to ./show, I see no messages at all. If I change redirect_to to render, the mess开发者_JAVA百科age appears. Still, isn't it intended for flash to work in the immediate subsequent requests?

BTW, I'm using Rails+Passenger setup, could it be so that redirected request goes to another application instance?


The rescue block is setting flash[:error], not flash[:notice]. Is your view actually rendering both?


Googled better and found this discussion:

http://www.mail-archive.com/activescaffold@googlegroups.com/msg04284.html

The solution is there: replace the plugin with

script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3 --force

Though I don't use ActiveScaffold, there is some legacy code that depends on render_component plugin. Updating plugin to branch version worked, though I'm planning to get rid of it completely.

0

精彩评论

暂无评论...
验证码 换一张
取 消