Comma in Update method

This week, I made couple CRUD apps. My app’s parameters were only ‘name’ and ‘last_name’. When I was running the update method in my terminal, the first parameter, ‘name’ was taking in an array of the name and the last name.

My code was as follows:

user.name = params[:name],
user.last_name = params[:last_name]

I then decided to delete the comma next to params[:name] and my problem went away.

I learned that if there is a comma next to the new value I want to change, the output will be the array of all of the params I put in. The correct code is below:

def update
the_id = params[:id]
user = User.find_by(id: the_id)
user.name = params[:name]
user.last_name = params[:last_name]
render json: user.as_json
end
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.