Michael Smith
Michael Smith

Reputation: 17

activerecord update wrong number of arguments

Sorry if this is a simple problem that has been explained before. I've done some research about my problem. I'm completely new to ruby and active record and I find the examples other have had with the wrong number of arguments too complicated for me to follow. So here is my simple one.

I'm trying to do a simple update using activerecord to a db. All I'm trying to do add a value to the title attribute that I left as nil when I created it in the first place.

vertigo is the variable I assigned using the .find method.

I'm typing in vertigo.update(title: 'Vertigo')

But I'm getting an error message saying

wrong number of arguments (1 for 2).

Here is more of session. I'm using Sinatra-tux >> vertigo = Movie.all D, [2015-04-20T11:11:38.890714 #3741] DEBUG -- : Movie Load (0.4ms) SELECT "movies".* FROM "movies" => #]>

vertigo.update title: "Vertigo" ArgumentError: wrong number of arguments (1 for 2) /home/michael/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/relation.rb:330:in update' (ripl):4:in'

Upvotes: 0

Views: 2384

Answers (1)

Yetti
Yetti

Reputation: 1710

find can return an array. It's entirely possible that your vertigo variable is actually an array.

Try to run

vertigo[0].update(title: 'Vertigo')

assuming you only want to change the first one.

Upvotes: 1

Related Questions