Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on 'save method' #1

Open
djohnkang opened this issue Mar 7, 2016 · 3 comments
Open

Error on 'save method' #1

djohnkang opened this issue Mar 7, 2016 · 3 comments

Comments

@djohnkang
Copy link

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 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.

@ejavaguy
Copy link
Contributor

ejavaguy commented Mar 7, 2016

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 [email protected] 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
#1
.

@ejavaguy
Copy link
Contributor

ejavaguy commented Mar 8, 2016

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

@nisevi
Copy link

nisevi commented Aug 29, 2016

@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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants