Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAaron Feltman
8,434 PointsUpdate the Pet object with the list of parameters returned from permit.
I am on step 4 of 5 on this challenge. below is the code I am using.
I have tried using just pet.update(pet_params) but it fails as well.
def update
@pet = Pet.find(params[:id])
params.require(:pet).permit(:name)
@pet = pet.update(pet_params)
end
class PetsController < ApplicationController
def show
@pet = Pet.find(params[:id])
end
def edit
@pet = Pet.find(params[:id])
end
def update
@pet = Pet.find(params[:id])
params.require(:pet).permit(:name)
@pet = pet.update(pet_params)
end
end
3 Answers
Nickolas Fuentes
14,016 PointsThis line of code worked for me!
def update
@pet = Pet.find(params[:id])
params.require(:pet).permit(:name)
@pet.update(params)
end
Jay McGavren
Treehouse TeacherYour current problems are being caused by the code pet.update(pet_params)
on line 14. There is no such variable as pet
in your code; pet
and @pet
are two different variables. Did you mean @pet
?
Adriana Cabrera
14,618 PointsThis is another way and what works for me too. I just want to share
def create # YOUR CODE HERE parametros = params.require(:pet).permit(:name) @pet = Pet.new(parametros) @pet.save redirect_to @pet
end