firstdraft / draft_generators

Rails generators that help beginners learn to program.
MIT License
2 stars 3 forks source link

New querying style in `draft:resource` #91

Closed raghubetina closed 4 years ago

raghubetina commented 4 years ago

Let's update draft:resource to use the new style for querying that we've been using in class: first put the Whatever::ActiveRecord_Relation in a variable called matching_whatevers, then proceed to do an .at(0) or .order to produce the instance variable.

def index
  matching_whatevers = Whatever.all

  @list_of_whatevers = matching_whatevers.order({ :created_at => :desc })

  render({ :template => "whatever_templates/index.html.erb" })
end
def show # edit, update, destroy
  the_id = params.fetch("path_id")

  matching_whatevers = Whatever.where({ :id => the_id })

  @the_whatever = matching_whatevers.at(0)

  render({ :template => "whatever_templates/show.html.erb" })
end