views:

106

answers:

2

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 message 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?

+1  A: 

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

zetetic
It is, of course.
xyzman
Indeed I thought this, what if a rescue occurs before the flash[:notice], then it will never be displayed.
Kezzer
A: 

Googled better and found this discussion:

http://www.mail-archive.com/[email protected]/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.

xyzman