Skip to content

Instantly share code, notes, and snippets.

@jcdavison
Last active August 29, 2015 14:16
Show Gist options
  • Save jcdavison/2a85f8766858990fe913 to your computer and use it in GitHub Desktop.
Save jcdavison/2a85f8766858990fe913 to your computer and use it in GitHub Desktop.
code-review

Hi Russell,

http://cl.ly/image/0B2h1L1i2J41/Image%202015-03-06%20at%209.52.07%20AM.png

Can you be more clear about what IS happening when you try to save your new item?

I'm guessing the lines of code involved are lines 185-193 in https://github.com/russellmiller3/CouchRocket/blob/master/CouchRocket.rb

  @item = Item.new(item_attrs)
  @item.original_price = To_Cents(@item.original_price)
  @item.asking_price = To_Cents(@item.asking_price)
  @item.save!
  @item.errors.each do |error|
    puts error
  end
  1. What does @item point to on the line AFTER you set it equal to the call to Item.new()?
  2. What happens if you insert a binding.pry on the line after you set the value of asking_price and call @item.valid? ?
  3. Adding the ! to your call to .save!() tells the ORM to return validation/save errors back to you, what happens if you change your call to save! to puts @item.save! ?

In the general sense, is there a difference between printing the return value of @item.save! and iterating through the .errors object and printing the contents (I don't know personally but this seems like an opportunity for exepcation and actuality to diverge)?

Maybe investigate my questions above and post back in this gist (or another one) some screenshots or terminal outputs?

❤️ JD

@russellmiller3
Copy link

Some really useful tips, thanks John!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment