Women in Technology

Hear us Roar



Article:
  Rolling with Ruby on Rails, Part 2
Subject:   "Showing recipes in a category" code
Date:   2005-03-04 16:56:48
From:   petercooper
Response to: "Showing recipes in a category" code

Not sure why there's a ? in there, as I copy and pasted from something I said on IRC :-) But anyway it should be something like:


@recipes = Category.find(@params['category']?).recipes


Full Threads Newest First

Showing messages 1 through 3 of 3.

  • "Showing recipes in a category" code
    2005-03-04 16:57:28  petercooper [View]

    Okay, I guess this system puts in random question marks for some reason. Sorry folks :)
  • "Showing recipes in a category" code
    2005-03-20 14:27:35  garrowsmith [View]

    Can this technique be adapted... say I wanted to list all recipies but sort them alphabetically by category. Is there a neat way to do this?
    • Curt Hibbs photo "Showing recipes in a category" code
      2005-03-20 17:18:44  Curt Hibbs | O'Reilly AuthorO'Reilly Blogger [View]

      Well, one way to do it would be to explicitly specify the SQL and use ORDER BY to do the sorting. Something like this:

      @recipes = Recipe.find_by_sql("SELECT * FROM recipies ORDER BY category_id")