Philip Rhoades
2006-Jan-06 05:57 UTC
[Rails] Cookbook recipes eg - ordering categories in the recipe pull-down box
People, I can order categories when looking at the categories list page but how do I change the recipe page to list the categories in alpha order in the recipe pull-down box?:> <p><b>Category:</b><br> > <select name="recipe[category_id]"> > <% @categories.each do |category| %> > <option value="<%= category.id %>" > <%= '' selected'' if category.id == @recipe.category_id %>> > <%= category.name %> > </option> > <% end %> > </select></p>Thanks, Phil. -- Philip Rhoades Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275) GPO Box 3411 Sydney NSW 2001 Australia Mobile: +61:(0)411-185-652 Fax: +61:(0)2-8221-9599 E-mail: phil@pricom.com.au
Kevin Olbrich
2006-Jan-06 06:26 UTC
[Rails] Re: Cookbook recipes eg - ordering categories in the recipe
In your controller just modify the query that loads the @categories variable to return the rows in the correct sort order. Something like... @categories = Categories.find(:all, :order=>"name") -- Posted via http://www.ruby-forum.com/.
Alain Ravet
2006-Jan-06 12:53 UTC
[Rails] Re: Cookbook recipes eg - ordering categories in the recipe
Philip, Have a look at http://blog.teksol.info/articles/2006/01/03/belongs_to-user-interface-take-ii It shows you - how to order, and also - how to validate for presence - how to highlight for validation error Alain -- Posted via http://www.ruby-forum.com/.
Chris Hall
2006-Jan-06 13:50 UTC
[Rails] Cookbook recipes eg - ordering categories in the recipe pull-down box
in recipe_controller.rb:
def show
@recipe = Recipe.find(params[:id])
@categories_for_select = Category.find(:all, :order =>
"name").collect {
|c| [c.name, c.id] }
end
in show.rhtml:
<%= select "recipe", "category_id",
@categories_for_select %>
the option that = @recipe.category_id will automatically be selected.
On 1/6/06, Philip Rhoades <phil@pricom.com.au>
wrote:>
> People,
>
> I can order categories when looking at the categories list page but how
> do I change the recipe page to list the categories in alpha order in the
> recipe pull-down box?:
>
>
> > <p><b>Category:</b><br>
> > <select name="recipe[category_id]">
> > <% @categories.each do |category| %>
> > <option value="<%= category.id %>"
> > <%= '' selected'' if category.id ==
@recipe.category_id %>>
> > <%= category.name %>
> > </option>
> > <% end %>
> > </select></p>
>
>
> Thanks,
>
> Phil.
> --
> Philip Rhoades
>
> Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275)
> GPO Box 3411
> Sydney NSW 2001
> Australia
> Mobile: +61:(0)411-185-652
> Fax: +61:(0)2-8221-9599
> E-mail: phil@pricom.com.au
>
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060106/36898c8a/attachment.html