If you can? in Ruby on Rails

In the Ruby on Rails application that I inherited from someone, I have code that looks like this

<% if can? :create, :objects %> <%= link_to 'Add New Object', new_object_path %> 

This web application has a login and users have different permissions defined in the table named groups_roles (in which groups (for example, admin, user) there are roles (for example, adding new objects))

I want to add new permissions, so where can I do this? Where are these things defined? How does Ruby know which table to get the different permissions from, and how does it know that :create and :objects are in the code above?

+4
source share
2 answers

The app seems to be using cancan by ryan bates stone. You can specify permissions in the file app/models/ability.rb .

It simply reads the ability file to determine if the user can perform an action or not. These actions correspond to the actions that you defined in the controller class.

There is a great wiki in Kankan in its github repository. In addition, screencast by ryan is a great place to start.

+4
source

I don’t know how the application works, but can? comes from cancan gem . See screencast .

+2
source

Source: https://habr.com/ru/post/1484063/