Created
April 8, 2015 22:24
-
-
Save alexdunae/b1fd2418c8d34709777d to your computer and use it in GitHub Desktop.
kerene apr 8
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
# goes to PagesController, home action | |
root 'pages#home' | |
class CharacterImporter | |
def initialize(character) | |
@character = character | |
end | |
def do_it | |
# do the importing and assigning | |
# build URL | |
# get JSON from server | |
# assign JSON data to @character | |
@character.save | |
end | |
end | |
class Character # model | |
def load_from_api | |
CharacterImporter.new(self).do_it! | |
end | |
end | |
# in controller, after create (or update?) you can run | |
@character.load_from_api | |
class User | |
def has_pet?(pet_id) | |
pet_ids.include?(pet_id) | |
end | |
def pet_ids | |
# look them up in the database | |
end | |
end | |
# view | |
pets.each do |pet| | |
if current_user.has_pet?(pet.id) | |
#yeah | |
else | |
#no | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment