Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-3.1cancan

hide or show content with CanCan based on role?


I need to hide some form fields in a form when a user is not a certain role. How could that be done? From the docs I know you can give access to certain actions like show, update or just manage

But how to do something like if user.role? :admin


Solution

  •   if cannot? :manage ,Articles
      flash[:notice] = "you are not authorized to manage articles"
    
      end