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.
Related
I have the rails admin gem to see the user-friendly DB of my app. In this DB I have a lot of libraries, and I was wondering if there was a way that only certain admins could access certain libraries.
For example, admin user with email library123#admin.com can only see the details from library 123 in the rails admin DB, so this admin will only be able to access the URL
https://my-app.com/admin/library/35 and not https://my-app.com/admin/library or
https://my-app.com/admin.
I use devise for authentication to the rails admin and I do not use any gem for authorization.
I was thinking of adding a column to users with relation to the library to know which library each user belongs to, however, I am stuck thinking how would I say to the rails admin only permit to see the library this user belongs to.
assuming you have #admin? (or similar) implemented in the user model:
authenticate :user, ->(user) { user.admin? } do
# mount your restricted routes
end
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
To explain it in a sentence, I am asking if it is possible to use the ActiveAdmin gem to create admin pages specific to admin users, i.e. each admin user only gets to see models and associating models specific to him. If so, how would I implement this?
To further explain my situation, I have a model called Sponsor(who would essentially be the admin users), and they put up different offers(another model that belongs to Sponsor) for users to redeem. So what I am trying to do is create an admin page where each sponsor gets his own admin credentials, and the admin page only shows the information that relates to this sponsor, i.e. the information regarding the offers this sponsor put up, and all relating models and its details. Is this possible to implement using the ActiveAdmin gem or any other gems for that matter?
I would rather not implement this from scratch if there are gems out there that I could use. Any suggestions?
I haven't tried this myself but it should be easily achievable in ActiveAdmin
either by changing the default scope on per controller basis or by using AuthorizationAdapter.
We'd like all users to be able to access ActiveAdmin, however, we would like to limit the creation of new users to specified administrators. The ideal outcome would be that only administrators see the users resource.
Currently, any user can go on to users.rb and create a new user. How do I limit this so that only specified administrators can create users? How do I stop users from seeing this resource unless they are specified as an administrator?
Do I need to add an admin attribute to the users model? From there what do I do?
Using Rails 4 with Devise.
I only have a users.rb model, no adminusers model.
When installing ActiveAdmin I used:
rails g active_admin:install User # creates / edits the class for use with Devise
Thanks very much for your help!
I think you need some ability managment:
https://github.com/CanCanCommunity/cancancan
https://github.com/activeadmin/activeadmin/blob/master/docs/13-authorization-adapter.md#using-the-cancan-adapter
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".