Forum: Ruby on Rails probably easy q: flash before redirect

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Vince W. (Guest)
on 2006-04-17 23:47
I'm a little perplexed why this isn't working:

private
        def check_authorization
                user = User.find(session[:user])
                if user.level == 100
                        flash[:notice] = "welcome, admin"
                else
                   flash[:notice] = "ha ha"
                   redirect_to :controller =>"account", :action
=>"signup"
                   flash[:notice] = "You are *not* an admin!!"
        end
        end
end


The first part (when user.level == 100) is ok but in the 2nd part it
goes directly to account/signup without displaying either flash message.
I've tried putting it before the redirect, after the redirect, both,
etc.  nothing.

What'd I miss?
Bryan D. (Guest)
on 2006-04-18 00:03
Vince W. wrote:
> I'm a little perplexed why this isn't working:
>
> private
>         def check_authorization
>                 user = User.find(session[:user])
>                 if user.level == 100
>                         flash[:notice] = "welcome, admin"
>                 else
>                    flash[:notice] = "ha ha"
>                    redirect_to :controller =>"account", :action
> =>"signup"
>                    flash[:notice] = "You are *not* an admin!!"
>         end
>         end
> end
>
>
> The first part (when user.level == 100) is ok but in the 2nd part it
> goes directly to account/signup without displaying either flash message.
> I've tried putting it before the redirect, after the redirect, both,
> etc.  nothing.
>
> What'd I miss?

Maybe a stupid question, but do you actually print out flash[:notice]
anywhere on the signup page? I assume the check_authorization view has
the print statement in it.
Vince W. (Guest)
on 2006-04-18 00:11
> Maybe a stupid question, but do you actually print out flash[:notice]
> anywhere on the signup page? I assume the check_authorization view has
> the print statement in it.

Actually not a stupid question at all.. that's exactly what it was.
Learn something new every day..

Thanks very much!
This topic is locked and can not be replied to.