hi all I am working on authorizations and making ...
# avo-2
l
hi all I am working on authorizations and making use of what is described here: https://docs.avohq.io/2.0/authorization.html#policies and it works perfectly. Now, I have this case where I am blocked: I have a model "session_execution.rb", which
Copy code
belongs_to :session
has_many :session_execution_attendances
has_many :farmers, through: :session_execution_attendances
and I would like to hide the "Create new farmer" button in the "session execution" show. In my "session_execution_policy.rb" I have tried this:
Copy code
def create_session_farmers?
    false
  end
but without success. Could it be that I am missing something because of the has_many through relation? Thanks.
l
Hey there
the
def create_{association}?
method must match the if of the field, which matches with the association name
the association name is
farmers
so the methdo should be
create_farmers?
can you try that and let me know if it works?
l
ufff thanks Adrian 😅 I first tried with "create_session_execution_attendances", which did not work. Then I thought that it should be "create_farmers" but wrote "create_session_farmers" 🤦 🤦 🤦 with 'create_farmers' it works perfectly, thanks !
and sorry for disturbing, mea culpa
l
no worries!
I'm glad it's fixed
4 Views