Search code examples
ruby-on-railsruby-on-rails-4controllers

Controller logic for two different type of users


In my project i have three different categories of users:

  • Guest
  • Registered
  • Admin

If a Registered user is logged in, I want to show them (if they click on a button) their orders.

The Admin instead can see the orders of all the users. I can use OrdersController to show things to the Registered user.

Is it necessary to create a new controller for the Admin , or I can use a if the user is a admin do this clause in the same controller(say OrdersController) that I use for the Registered users?


Solution

  • There's no single right answer to this question, it really depends a lot on your code, your app, your use cases, and a whole bunch of other detail that you haven't provided (and that this is not the best forum for).

    So, generally the administration tasks are so distinct from the regular users that people create new controllers for them, usually under their own Admin:: namespace.