Skip to content

Instantly share code, notes, and snippets.

@alexdunae
Created April 8, 2015 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexdunae/b1fd2418c8d34709777d to your computer and use it in GitHub Desktop.
Save alexdunae/b1fd2418c8d34709777d to your computer and use it in GitHub Desktop.
kerene apr 8
# 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