ruby on rails - How do I use Devise and ActiveAdmin for the same User model? -
i have activeadmin , devise working users. use devise log in regular non-admin users same user model. how can this? (i want have admin
flag in user model admins.) tried adding 2nd line routes.rb
devise_for :users, activeadmin::devise.config devise_for :users
but gave error when tried list routes
>rake routes dl deprecated, please use fiddle rake aborted! argumenterror: invalid route name, in use: 'new_user_session' may have defined 2 routes same name using `:as` option, or may overriding route defined resource same naming. latter, can restrict routes created `resources` explained here: http://guides.rubyonrails.org/routing.html#restricting-the-routes-created
i've created authorization adapter checks user.admin == true
, working ok activeadmin. https://github.com/activeadmin/activeadmin/blob/master/docs/13-authorization-adapter.md
but ended doing this
devise 3.4.1
activeadmin 1.0.0.pre1
rails 4.2.1
routes.rb
devise_for :admin_users, {class_name: 'user'}.merge(activeadmin::devise.config) activeadmin.routes(self) devise_for :users resources :users
application_controller.rb
def access_denied(exception) redirect_to root_path, alert: exception.message end
config/initializers/active_admin.rb
config.authorization_adapter = activeadminadapter config.on_unauthorized_access = :access_denied
(and changing methods _user
admin_user
.)
app/models/active_admin_adapter.rb
class activeadminadapter < activeadmin::authorizationadapter def authorized?(action, subject = nil) user.admin == true end end
and
rails generate migration add_admin_to_users admin:boolean
Comments
Post a Comment