Rails - TypeError: nil is neither a symbol nor a string when updating


bitwise

I am trying to update properties. This is a boolean value that defaults to false. In my method, I do a query to find the right user. Then I tried to update the user by flipping owner booleanset to true. What I'm getting is a very strange error because it's updating the method, but it's also giving this errorTypeError: nil is not a symbol nor a string

I just want to know what I'm doing wrong.

controller

def update
  membership = current_account.account_memberships.find_by(user_id: params[:id])
  membership.update(owner: true)
end

HTML

<%= link_to "Owner", account_membership_path(user), {
  class: "icon icon-owner-upgrade",
  method: :patch,
} %>
Vadim

If you want to update records on changing model - it might just be "foreing key", but no "primary key". If you add a line "self.primary_key" like this, it solves the problem:

YourDependentRecord <ApplicationRecord
  self.primary_key = 'USER_ID'

where 'user_id' - is the primary key in the main model.

Related


How to fix "TypeError - nil is not a symbol nor a string:"?

Moriarty I have two actions form_oneand form_two. One is an alias for the other. FormsController def form_one @selected_tab = { form_type => :selected } end alias :form_two :form_one private def form_type @form_type = params[:form_type] end I have decl

How to fix "TypeError - nil is not a symbol nor a string:"?

Moriarty I have two actions form_oneand form_two. One is an alias for the other. FormsController def form_one @selected_tab = { form_type => :selected } end alias :form_two :form_one private def form_type @form_type = params[:form_type] end I have decl

Rails - in "private": nil is not a symbol (TypeError)

furniture It appears in the production server and not in the local server, the problem is in the Subscribe_Controller, where I define which parameters to send to MailChimp as a mailing list, this is the error log from $heroku run rails console. /app/app/contro

rails 4 activerecord TypeError nil is not a symbol

Chris Hough It appears that a table in sql server is placed nilin the select statement. I don't know how to fix this, if I switch to any other table I can easily get the first record. Has anyone else dealt with this error? I took the table apart and built a vi

rails 4 activerecord TypeError nil is not a symbol

Chris Hough It appears that a table in sql server is placed nilin the select statement. I don't know how to fix this, if I switch to any other table I can easily get the first record. Has anyone else dealt with this error? I took the table apart and built a vi

rails 4 activerecord TypeError nil is not a symbol

Chris Hough It appears that a table in sql server is placed nilin the select statement. I don't know how to fix this, if I switch to any other table I can easily get the first record. Has anyone else dealt with this error? I took the table apart and built a vi

rails 4 activerecord TypeError nil is not a symbol

Chris Hough It appears that a table in sql server is placed nilin the select statement. I don't know how to fix this, if I switch to any other table I can easily get the first record. Has anyone else dealt with this error? I took the table apart and built a vi

timeit ValueError: stmt is neither a string nor a callable

liang li : I've been playing timeitaround in Python and I've run into a strange problem. I define a simple function add. timeitWorks when I pass addtwo string parameters. But ValueError: stmt is neither a string nor callablewhen I pass addtwo intparameters it

PHP - Check variable is neither empty nor string

King Kong I am writing php code which is linked with database. For example if I put the value on the php code $ pid = somevalue。 This value will pass it to the next php file. I want to check that this somevalue is not empty or not a string value if( some condi

timeit ValueError: stmt is neither a string nor a callable

liang li : I've been playing timeitaround in Python and I've run into a strange problem. I define a simple function add. timeitWorks when I pass addtwo string parameters. But ValueError: stmt is neither a string nor callablewhen I pass addtwo intparameters it

TypeError: nil is not a symbol

Kevin McCabe Just trying to save with ActiveRecord, I keep getting "TypeError: nil is not a symbol" if card_data[:card] and card_data[:deck] e = self.find_or_create_by(card_id: card_data[:card].id, deck_id: card_data[:deck].id, main: main) e.card = card_da

TypeError: nil is not a symbol

Kevin McCabe Just trying to save with ActiveRecord, I keep getting "TypeError: nil is not a symbol" if card_data[:card] and card_data[:deck] e = self.find_or_create_by(card_id: card_data[:card].id, deck_id: card_data[:deck].id, main: main) e.card = card_da

TypeError: nil is not a symbol

Kevin McCabe Just trying to save with ActiveRecord, I keep getting "TypeError: nil is not a symbol" if card_data[:card] and card_data[:deck] e = self.find_or_create_by(card_id: card_data[:card].id, deck_id: card_data[:deck].id, main: main) e.card = card_da

TypeError: nil is not a symbol

Kevin McCabe Just trying to save with ActiveRecord, I keep getting "TypeError: nil is not a symbol" if card_data[:card] and card_data[:deck] e = self.find_or_create_by(card_id: card_data[:card].id, deck_id: card_data[:deck].id, main: main) e.card = card_da

Docker rails neither installs gem correctly nor bundles it

critical stone I tried installing gravity gems and then doing the following: put in gem 'gravtastic'Gemfile Runsudo docker-compose run web bundle install This output includes gravity Runsudo docker-compose up I try to run sudo docker-compose run web gem instal

How to print status if neither true nor false in Rails

mouse 007 I have a model named ProjectSiteand another named model ManagerRemarkthat takes a decision boolean . ProjectSiteThere are many ManageRemark. The default value is decisionnil. How do I print the status as "pending" when it doesn't ManagerRemark? Here

Docker rails neither installs gem correctly nor bundles it

critical stone I tried installing gravity gems and then doing the following: put in gem 'gravtastic'Gemfile runningsudo docker-compose run web bundle install This output includes gravity runningsudo docker-compose up I try to run sudo docker-compose run web ge