Redirect from a template based on Devise

20 views
Skip to first unread message

Michael Davis

unread,
Jun 13, 2016, 12:33:48 PM6/13/16
to Ruby on Rails: Talk
Hi,

I'm trying to lock down a specfic template in my rails application to a particular user type, but only have a sinlge user model at the moment. There is a method that determines if the logged in user can access that page. Is this not possible within rails, and I have to do this at the controller level.

I was hoping that I could just simply put something like this into the template.

<%= current_user.reviewer? redirect: 401 %>

but I can't find anything that seems able to do a redirect from the template.

Cheers
Michael

Greg Navis

unread,
Jun 13, 2016, 1:42:59 PM6/13/16
to rubyonra...@googlegroups.com
I'm not sure whether this is possible at all. Even if it is, it'll violate the principle of least surprise. Could you tell a bit more about what you want to achieve so we might be able to suggest an alternative design?
--
Greg Navis
I help tech companies to scale Heroku-hosted Rails apps.

Michael Davis

unread,
Jun 14, 2016, 5:31:03 AM6/14/16
to Ruby on Rails: Talk
Hi Greg,

I was trying to prevent non reviewers from seeing the full list of users by raising an unathorised error within the Devise users template.

I've modified the display so they can only see their own account, and I realise I could do this by customising the controller, but I wanted something quick and easy.

Cheers
Michael
Reply all
Reply to author
Forward
0 new messages