2

I am sure it is something small I am not seeing, but I am getting this wrong number of arguments (1 for 2) when I try to update information via a form, in rails 4.

here is my controller action:

def update
    @lion = Lion.find(params[:id])
    @lion = Lion.update(lion_params)
    redirect_to lion(@lion)
end

and here are the lion_params in the private method for that controller

def lion_params
     params.require(:lion).permit(:name, :about, :weight, :health, :health_notes, :photo_url, :trainer_id)
end

All the information is present in the form, so I am not quite sure where this error is coming from.

HolyMoly
  • 2,020
  • 3
  • 22
  • 35
  • 4
    I have a feeling you meant `@lion.update(lion_params)` and not `@lion = Lion.update(lion_params)` – Justin Wood Aug 02 '15 at 16:38
  • on my. I don't know what's worse, making the silly mistake or looking at it so many times and not catching it. lol. thanks for the fresh set of eyes!! :) – HolyMoly Aug 02 '15 at 16:42
  • As an off topic comment, when writing Ruby code you will probably want to stick with a 2 space indentation. That is what is used within the Ruby community. – Justin Wood Aug 02 '15 at 16:43
  • Thank you for pointing that out as well, I do want to follow convention and best-practice :) – HolyMoly Aug 02 '15 at 16:51

1 Answers1

3

You want to use update_attributes on @lion, not `update:

# The bang `!` is used to raise in case of validation errors
@lion.update_attributes!(lion_params)

Check this article which explains all the differences between update, update_all, update_attribute, update_attributes

Also ensure your last line is redirect_to lion_url(@lion) (lion() doesn't exist), it's important to use _url method because it follows HTTP specifications

Community
  • 1
  • 1
Francesco Belladonna
  • 11,361
  • 12
  • 77
  • 147
  • thank you :) Justin Wood found the error (he responded in a comment however so I couldn't mark it as answered), but I do appreciate the link and will definitely be checking out update_attributes! – HolyMoly Aug 02 '15 at 18:01