mercredi 21 septembre 2016

How can I authenticate a user with admin attribute for rails_admin with devise

I am fairly new to ruby on rails. I habe set up a mysql database, connected it with a rails app, installed the devise gem and rails_admin gem. So far so good, everything works as it should. Now I also added a usergroup attribute to the users table, to identify different user group. Only "admin" should be allowed to access rails admin. I already use the predefined commands in /app/config/initializers/rails_admin.rb

   RailsAdmin.config do |config|

  ### Popular gems integration

  ## == Devise ==
   config.authenticate_with do
     warden.authenticate! scope: :admin
   end
   config.current_user_method(&:current_user)

  ## == Cancan ==
  # config.authorize_with :cancan

  ## == Pundit ==
  # config.authorize_with :pundit

  ## == PaperTrail ==
  # config.audit_with :paper_trail, 'User', 'PaperTrail::Version' # PaperTrail >= 3.0.0

  ### More at http://ift.tt/1zzoq7G

  ## == Gravatar integration ==
  ## To disable Gravatar integration in Navigation Bar set to false
  # config.show_gravatar true

  config.actions do
    dashboard                     # mandatory
    index                         # mandatory
    new
    export
    bulk_delete
    show
    edit
    delete
    show_in_app

    ## With an audit adapter, you can add:
    # history_index
    # history_show
  end
end

This works so far that you have to login before you can access the page. Now there also has to be a check wether current_user.usergroup = 'admin'.

In devise this is also explained as one possible method to 'handle' usergroups. http://ift.tt/1klqdGy

But I am pretty confused how to insert this check into the config that way.

Aucun commentaire:

Enregistrer un commentaire