Reputation: 265
The question may not be that complicated, but i am confuse. I have two users i.e. Student and Teacher, and for those i want separate models, controllers and views. I want teacher to use /t/sign_up
and for student /s/sign_up
. I am using devise for authentication, I know it is possible because that's how active admin works.
Upvotes: 18
Views: 11078
Reputation: 1710
Provided you have already generated multiple models and views with devise, and just want to change the path name, you can do that configuring config/routes.rb:
devise_for :students, path: 's'
devise_for :teachers, path: 't'
which will replace your routes like this:
http://localhost:3000/s/sign_up
http://localhost:3000/t/sign_up
If you want to have your views based on different models, you can configure config.scoped_views = true
inside config/initializers/devise.rb
file and generate views for that model:
rails g devise:views students
And if you want to customize each controller, you can generate their controller files like this:
rails generate devise:controllers students
This will create controllers based on model name, thus you can define them in your routes:
devise_for :students, path: 's', controllers: { sessions: "students/sessions" }
Upvotes: 28