Skip to content

Instantly share code, notes, and snippets.

@MarcoMorawec
Last active January 23, 2024 16:05
Show Gist options
  • Save MarcoMorawec/6571008 to your computer and use it in GitHub Desktop.
Save MarcoMorawec/6571008 to your computer and use it in GitHub Desktop.

Important Model Methods

I don't have an object yet

  • all Model.all => fetch all the items from the database
  • create Model.create(:hour => 1, :emotion => "super stoked")
    => create a new model in the database
  • new Model.new => build a new model but don't save it
  • first Model.first => fetches the first one
  • last Model.last => fetches the last one
  • find Model.find(1) => fetches one with the id we give it
  • where Model.where(:hour => 1, :emotion => 'happy') => fetch all of models that have the "hour" set to "1"

Ok I have an object

  • destroy Model.destroy => delete the item from the database
  • update_attributes Model.update_attributes(:hour => 3) => update the attributes on the model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment