Rails_admin, logging in with multiple models - ruby-on-rails

In rails_admin wiki with Devise it has example with only one model. I have two models Admin and Owner. I will define their roles with cancancan.
Is it possible to make more than one model, which uses Devise, able to login to rails_admin dashboard? I just can't find any examples.
Using only one model with diffrent roles may be bad solution, because there each of them will have very different attributes.

The only method I have found is to use inheritance.
I have Admin and User models in which I want to use my rails_admin. I have created Person model which will be parent class for both of them.
Then I added devise for Person with CanCan authorization.

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

Different roles attributes with CanCan, Devise and ActiveAdmin

I've discovered yesterday a tutorial that explains how to implement a role based single user model with Devise, ActiveAdmin and CanCan : http://renisoft.com/devise-activeadmin-cancan-single-user-model/. Yet, I'm new to rails, and I was wondering if it is possible to implement such a solution with roles that have different attributes. For instance, my users will have email, forename, surname, password and will share it with the other roles. But my seller role will have many attributes, my admin and my buyers will have others. Is it something possible to implement with those ruby gems ?
Thanks in advance for your answer.
Users and roles are two different things. Roles haven't got any attributes, but Users have.
However check this:
Rolify is a great Role management library for rails: https://github.com/EppO/rolify

devise and multiple users

I am trying to have Devise create a single User model and have different roles be a separate model. My User model (from rails g devise User) has a email, first name, last name, and role field.
The roles are admin, spectator, competitor. So, I created admin, spectator, and competitor models who all inherit from the User model.
I followed the top answer from devise and multiple "user" models and I can create a user. However, my competitor model migration also has other information such as contest name and location that are not required for the other models. When I do Competitor.create() and put in the necessary information for creating a devise User, the User gets stored in the database even though I have null constraints on the competitor model for contest name and location.
When I do Spectator.all, the recently created competitor data shows up which I thought it shouldn't....
My question is how should I be setting this up so that a competitor user doesn't get created unless his contest name and location is provided.
Another question is why when I do Spectator.all is the competitor's information displaying?
There is a much better way to use devise for multiple users.
Use Rolify Gem
It makes development much easier faster and more secure. You can have the configuration as per your requirement in the question "Single User model and each roles have a separate model"
Tutorial for using Rolify gem + Devise by Rolify Gem developers
If you want an authorization system, so go for CanCan created by Ryan Bates. With CanCan you can have many Roles. I am using it with devise with no problems. See Role Based Authorization and Separate Role Model. And check this ScreenCast about CanCan

How I can create with multiple types of users, using a simple login with Devise?

I'm using Mongoid, Devise and Rails 3.1.
I have four models: Students, Teacher, Parents and School (the main account). All them will log in on system. But, I don't want create four ways to login. I want create an unique login method using anyone this models, but with respectives roles (This is the minor problem, I already can do that with CanCan).
Anybody have a easy solution, without create a programming-hell?
Actually, people logging on to your system are all Users. So either you choose to let the classesTeacher, Student, Parent, SchoolRepresentative to inherit from User using STI.
Most of the times I prefer simply that a User has roles. And the role would then be teacher, student ...
The roles define what a user is allowed to see.
Hope this helps.

Rails 3, Devise, Multiple Roles Sharing Same Views

I'm writing a trading system and I have 3 models/roles: Buyers, Sellers and Administrators. I have generated the devise views for each of the models but I would like to use the same sign in, forgotten password pages etc. for them, rather than maintaining 3 sets of views, is there a way of doing this?
The buyer and seller have similar fields (forename, surname, email address, telephone etc.), is it possible to use STI with devise and is it fairly straightforward? At the moment I have 3 separate models with no inheritance.
You can simply have a single User model with a :role attribute and also implement a simple ACL via CanCan or decl_auth (gems). This way they will all sign in etc. via the same session. Devise and CanCan is quite a popular approach and well documented online and in their respective Github wiki's.
For administrators, you can modify your validations to skip on the extra attributes and leave them as blank in the DB.

Resources