You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reuse Devise ( Authentication with gem 'devise') and CanCan (Authorization with
gem 'cancan') for access control :
in lib/my_app/devise_auth.rb
moduleMyApp::DeviseAuthdefauthenticateifcurrent_userability=Ability.new(current_user)returntrueifability.can?(:manage,"Cms::Site")raiseCanCan::AccessDeniedelsescope=Devise::Mapping.find_scope!(:user)session["#{scope}_return_to"]=new_cms_admin_site_path(:locale=>I18n.locale)# if localized...redirect_toadmin_sign_in_pathendendend
In config/initializers/comfortable_mexican_sofa.rb
config.admin_auth='MyApp::DeviseAuth'
In models/ability.rb
definitialize(user)alias_action:index,:show,:to=>:readalias_action:create,:update,:to=>:manage# define user abilities here ....user ||= User.new
...
ifuser.has_role?:admincan[:read,:manage],"Cms::Site"