If you want to break the request chain in a before filter, you need to
'throw(:halt)'.
def check_role
throw :halt, redirect('/admin') if session.user.role != :user
end
On Wed, Apr 28, 2010 at 8:20 PM, Dan Sosedov <[email protected]> wrote:
> Hello,
>
> I found a really strange bug (or maybe not bug, not sure) in merb.
>
> So, i have controller Settings which handles all user settings. But
> for different types of users (user, manager, admin) it supposed to be
> different. Settings pages are available for users only. For managers
> and admins it should redirect them to different route /admin.
>
> so my controller looks like this:
>
> class Settings < Application
> before :ensure_authenticated
> before :check_role
>
> private
>
> def check_role
> redirect "/admin" if session.user.role != :user
> end
>
> public
>
> def profile
> .... logic ....
> end
>
> ... all logic ...
> end
>
> But for some reason page is not redirected there. In actions log
> (stdout) it shows that redirect header was triggered correctly: merb :
> worker (port 4000) ~ Redirecting to: /admin (302).
> Thus, other user types does not have any information to show on
> settings page and thats why instead of redirect im getting exception
> that user objects were not found (nils).
>
> So, im really confused about such behavior of merb.
>
> Any ideas why?
>
> --
> You received this message because you are subscribed to the Google Groups
> "merb" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/merb?hl=en.
>
>
--
-jonah
--
You received this message because you are subscribed to the Google Groups
"merb" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/merb?hl=en.