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.
The devise gem is basically based on a warden gem, which gives an opportunity to build authorization direct on a Ruby Rack Stack. This gem is pretty straightforward and well documented. Warden fetches a request data and checks if the request includes valid credentials, according to a defined strategy.
Resource is an abstraction name of instance of a user. It can be configured in devise settings to work with Admin model or any other. By default it's the first devise role declared in your routes devise :users # resource is instance of User class devise :admins # resource is instance of Admin class.
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" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With