HolyMoly
HolyMoly

Reputation: 2080

Rails 4 wrong number of arguments (1 for 2) error for update

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.

Upvotes: 2

Views: 3281

Answers (1)

Francesco Belladonna
Francesco Belladonna

Reputation: 11689

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

Upvotes: 3

Related Questions