Create separate session for rails admin login - ruby-on-rails

I’m using Rails 4.2.1 and Devise and rails_admin and I’m quite new to Rails.
I need to add rails admin to my project. I need a separate login For rails admin. (I don't want to add a new column user for that. As admin and normal users are different) For that I added a new model Admin. I used devise for creating views and models. But now I need to add routes in routes for admin user having only sign in feature(No need for registration). Now I have all those features(registration,...). I also need a separate session apart from the user session. As I logout user, adminuser is also logging out.

To get seperate session please make changes in devise.rb
config.sign_out_all_scopes = false

Related

CRUD actions on a Devise User model - Rails 5

I'm working on a project that has a User Devise model and an Admin Devise model, and I want an Admin to be able to perform CRUD on the User model.
I've set up both Devise models following the Devise Wiki's How to Setup Multiple Devise User Models guide (including step 4 - exposing the scoped controllers).
This has given me the Devise views and controllers for confirmations, passwords, registrations, sessions and unlocks, but no users_controller to add CRUD actions to.
Could I simply create a users_controller and make sure it uses the correct users table in the database, or should I add CRUD actions to the registrations_controller?
Is the above advisable, or is there a more elegant way of setting up a CRUD interface for an Admin to be able to manage the User model?
Any help would be much appreciated.
Devise works only with sign_up/sign_in process. It assumes not only simple user creation, but some more things, like email sending.
So if you want to create/update/destroy users you need to create separate UsersController. It is better to add an admin namespace to it

devise for two models

I am building an app with "nested authentication" That means that I have a House modle (with devise) and a house has many users and once inside the House authentication, I would like the users to be able to sign in as well. I have also added a User model with Devise. My question is that right now I am getting errors because I the devise sign_up form that I have designed for Houses doesn't work for the User model. How do I create separate sign_up and sign_in forms for two different user models with devise? Or is there a better way to go about doing this? Thanks!
How do I create separate sign_up and sign_in forms for two different user models with devise?
rails g devise:views
This will create an app/views/devise.
Then: set "config.scoped_views = true" inside "config/initializers/devise.rb".
From the README:
After doing so, you will be able to have views based on the role like "users/sessions/new" and "admins/sessions/new". If no view is found within the scope, Devise will use the default view at "devise/sessions/new".

RoR Active Admin adding Users

This might be a very simple questions as I am just getting started with RoR and been doing as much learning through resources as possible. Basically I am using Active Admin to handle the admin portion of my application. What I am wondering about is creating a user model. I know Active Admin uses Devise for its autherzation so if run rails generate active_admin:resource Userit should create the user model the same way as if I ran it with Devise correct?
The end goal is to have the main front end page be a login for users that are created by the admin on Active Admin (no sign up from the front end) that will lead them to the secure information like Profile, orders, what ever.
What you're looking to do (assuming that you want to separate out the idea of Admin Users versus regular users) is first generate the new devise model as you normally would:
rails generate devise user
Then create a resource to manage them within active admin
rails generate active_admin:resource User
The rest is a standard devise integration assuming the pages are outside the scope of Active Admin.

Rails Devise allows 1 person to register

I am having a Rails app for personal use and it uses Devise for authentication. I want there is only one user for my app. In other words, how do I disable registration in Devise after there is already 1 user registered ?
I am thinking about creating a custom method in controller. But is there any good way to do this ?
You want to remove the :registerable option in the model. Then create your single account in your seed.rb and then just seed your app. No need to complicate things just for your own use.

User CRUD in web application that handles registration and login with Devise

I am currently working on application that is build on rails 3.0.9. All of a sudden the client decided that there should be a place to create a user and edit a user in the admin section of the website.
Now here is the case. The authentication and registration in the web application is handled by devise. If I try to implement a custom USER create method in my controller how should I hash the password in the very same way devise is doing so that I can store that in the database. This also applies to editing the already registered users as well.
I have tried to find the solution but no use. Any help in resolving this would be appreciated.
That's easy. You can setup another controller and form but set it up on your User model. Your form will need to include :email, :password, and :password_confirmation. When you do #user.save in your controller's create action, this will have devise take care of all the hashing requirements under the hood.
If you want to check that your save works (just for testing), add a bang at the end like #user.save! - this is only for testing. Either drop into rails console and you can see the newly added records or tail your log file.
Editing should work along the same lines and you can do #user.update_attribute() in your edit action, or #user.update_attributes() if you prefer mass assignment (this will be subject to any attr_accessible restrictions in your model)

Resources