admins and users same controller/model

14 views
Skip to first unread message

fugee ohu

unread,
Feb 19, 2017, 3:38:32 PM2/19/17
to Ruby on Rails: Talk
I have admins and users sharing the same controller and model
Admins have more liberties so users form is different view
For new and create actions for example should i write new actions to work with the users form submission or should i put a conditional express in my before_action
I had the creative idea that I could use authenticate_user|authenticate_admin for my callback but it seems there's no such thing but I can use a conditional expression What's the solution?

Colin Law

unread,
Feb 19, 2017, 4:48:26 PM2/19/17
to Ruby on Rails: Talk
In the new and create actions you can test the current user's role
(user or admin) and render a different view, or have a common view
with conditional code in the view (possibly calling different partials
for example), whichever is more appropriate for your particular case.

Colin

fugee ohu

unread,
Feb 19, 2017, 5:49:09 PM2/19/17
to Ruby on Rails: Talk

First I have to authenticate either before I can test for which in the new and create actions
 

Colin Law

unread,
Feb 20, 2017, 3:18:11 AM2/20/17
to Ruby on Rails: Talk
What has authentication got to do with role? Presumably you have a
login procedure, then in the action you just have to check that
someone is logged in and test for the role of current_user to decide
what to show them or whether to allow the create.

Colin
Message has been deleted
Message has been deleted

fugee ohu

unread,
Feb 21, 2017, 11:00:24 AM2/21/17
to Ruby on Rails: Talk

I went with adding a subdirectory for users under views Considering doing the same for controllers
Reply all
Reply to author
Forward
0 new messages