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 trial

Ruby

bessiebarnes
bessiebarnes
88,917 Points

Using =, assign pet a new name of "Sassie". I'm stuck on this challenge

pet = Pet.new pet.name = “Sassie” pet.save

bessiebarnes
bessiebarnes
88,917 Points

The challenge has 3 parts. The following is the first part which I passed.

(1) Calling Pet.all returns the following collection of records:

<ActiveRecord::Relation [

<Pet id: 1, name: "Tchai", birthdate: "2016-04-26", created_at: "2016-07-28 17:37:24", updated_at: "2016-07-28 17:37:24">,

<Pet id: 3, name: "Annie", birthdate: "2016-04-26", created_at: "2016-07-28 17:37:45", updated_at: "2016-07-28 17:37:45">, #<Pet id: 4, name: "Scottie", birthdate: "1983-05-17", created_at: "2016-08-17 21:19:49", updated_at: "2016-08-17 21:19:49">]

Retrieve the Pet record with an ID of 3, and store the model object in the pet variable.

answer: pet = Pet.find(3)

(2) Using =, assign pet a new name of "Sassie". is the second part of the challenge. I have tried a few variations but can't get anything to pass.

pet = Pet.name pet.name = “Sassie” pet.save

1 Answer

Oswaldo Rangel
Oswaldo Rangel
3,554 Points

Hi Bessie, in order to assign a new value to an existing pet object, you should first get the "pet" instance to modify, in this case something like this: pet = Pet.find(3)

this is where you assign the new value:

pet.name = "Sassie"

for the last step if it's required, you save changes to the database:

pet.save

Cheers and happy coding!