Last active
December 15, 2015 13:29
-
-
Save zeroeth/5268058 to your computer and use it in GitHub Desktop.
importbooks.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| response["books"].each do |book_hash| | |
| Book.from_json(book_hash) | |
| end | |
| class Book < AR | |
| def self.from_json(book_hash) | |
| self.new({image: book_hash["i"], whatever else}) | |
| end | |
| end | |
| # How to collect things 1 | |
| @list = [] | |
| response["books"].each do |book_hash| | |
| @list << Book.from_json(book_hash) | |
| # OR | |
| @list.push Book.from_json(book_hash) | |
| end | |
| # How to collect things 2 | |
| @list = response["books"].collect do |book_hash| | |
| Book.from_json(book_hash) | |
| end | |
| # How to train your dragon | |
| @response["books"].each do |book_hash| | |
| Book.from_json(book_hash).save | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment