Open djohnkang opened 8 years ago
Hmmmm. That was a late change I made to make the example look closer to the assignment. If you state it did not work, I obviously did not test it enough when making that change.
The main point about the change is that explicitly assigned and dynamically assigned _ids can be obtained using result.inserted_id.
I will review this evening what the assignment to @id caused.
thanks
On Mon, Mar 7, 2016 at 1:48 AM, John Kang notifications@github.com wrote:
It seems that there are some errors in the code on adding 'save method'
I tried this code
def save Rails.logger.debug {"saving #{self}"}
result=collection.insert_one(_id:@id, city:@city, state:@state, pop:@pop) @id=result.inserted_id
end
And it didn't work so I changed it in the same way in the lecture video like this,
self.class.collection.insert_one(_id:@id https://github.com/id, city: @city https://github.com/city, state:@state https://github.com/state, pop:@pop https://github.com/pop)
And this worked
Please check if it's right or wrong.
— Reply to this email directly or view it on GitHub https://github.com/jhu-ep-coursera/fullstack-course3-module1-zips/issues/1 .
Could you share with me a scenario that demonstrates the error you found?
Here is what I encountered with an adhoc script in the rails console
zip=Zip.new(:id=>"99999",:city=>"new city",:state=>"md",:population=>5) zip.save saving 99999: new city, md, pop=5 => "99999" zip.update(:population=>500) Zip.find(zip.id).population => 500
@ejavaguy , @biniprc I think this error is related to the PR that I opened here #4 and there is another one here #5 . I was following step by step what is mentioned in the README file when I found them.
Sorry that I did two separated PR but I discovered on different times.
Excellent course by the way :+1:
It seems that there are some errors in the code on adding 'save method'
I tried this code
def save Rails.logger.debug {"saving #{self}"}
end
And it didn't work so I changed it to the code in the lecture video like following,
self.class.collection.insert_one(_id:@id, city:@city, state:@state, pop:@pop)
And this worked
Please check if it's right or wrong.