I'm trying to update an attribute. It's a boolean with a default of false. In my method I make a query to find the right user. then I try to update that user by flipping the owner boolean
to true. It's a really strange error I'm getting because it's updating the method but it also sending out this error TypeError: nil is not a symbol nor a string
I'm just wondering what I'm doing wrong here.
def update
membership = current_account.account_memberships.find_by(user_id: params[:id])
membership.update(owner: true)
end
<%= link_to "Owner", account_membership_path(user), {
class: "icon icon-owner-upgrade",
method: :patch,
} %>
If you are trying to update the record in a dependent model, it possibly has only a foreign key, but no primary key. The problem can be solved if you add a line self.primary_key
like this:
class YourDependentRecord < ApplicationRecord
self.primary_key = 'user_id'
end
where 'user_id'
is the primary key in the master model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With