yop, http://rubyonrails.org/api/classes/ActionView/Helpers/FormHelper.html ici j''ai vu qu''on pouvait g?n?rer des ?l?ment d''un formulaire gr?ce des m?thodes. Apres quelque petite recherches j''ai trouv? comment g?n?rer un select <%= select(''category'', ''category.id'', Category.find_all.collect {|category| category.nom}) %> comment faire pour utiliser l''option selected ? Merci -- Bolo Michelin Blog [Flash & RoR] http://blog.developpez.com/?blog=30 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060425/7c030e11/attachment.html
oups sorry i wrote in French i would like to know how to add a ''selected option'' for selec box? <%= select(''recipes'', ''category.id'', Category.find_all.collect {|c| [ c.nom, c.id ] }) %> tks 2006/4/25, Bolo <malavoi@gmail.com>:> > yop, > > http://rubyonrails.org/api/classes/ActionView/Helpers/FormHelper.html > > ici j''ai vu qu''on pouvait g?n?rer des ?l?ment d''un formulaire gr?ce des > m?thodes. Apres quelque petite recherches j''ai trouv? comment g?n?rer un > select > > <%= select(''category'', ''category.id'', Category.find_all.collect > {|category| category.nom}) %> > > comment faire pour utiliser l''option selected ? > > Merci > -- > Bolo Michelin > Blog [Flash & RoR] http://blog.developpez.com/?blog=30 >-- Bolo Michelin Blog [Flash & RoR] http://blog.developpez.com/?blog=30 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060425/c3bfb47e/attachment-0001.html
> i would like to know how to add a ''selected option'' for selec box?I assume you are looking to have the select box automatically select the recipe category if it already exists? If that''s the case, you need to change your helper to the following: <%= select(''recipes'', ''category_id'', Category.find_all.collect {|c| [c.nom, c.id]}) %> The select helper method will call the category_id method on your @recipes object and automatically add the selected="selected" attribute for the correct option. As an aside, you might also be interested in my acts_as_dropdown plugin for helping to make these select boxes cleaner. You can find out more about it here: http://delynnberry.com/pages/acts_as_dropdown, but it basically allows you to do this: class Category < ActiveRecord::Base acts_as_dropdown :text => "nom" end <%= select(''recipes'', ''category_id'', Category.to_dropdown) %> -- DeLynn Berry delynn@gmail.com http://delynnberry.com
Hello Delynn assume you are looking to have the select box automatically select> the recipe category if it already exists?yes :) If that''s the case, you need> to change your helper to the following: > > <%= select(''recipes'', ''category_id'', Category.find_all.collect {|c| > [c.nom, c.id]}) %>okidoki> As an aside, you might also be interested in my acts_as_dropdown > plugin for helping to make these select boxes cleaner. You can find > out more about it here: http://delynnberry.com/pages/acts_as_dropdown, > but it basically allows you to do this: > > class Category < ActiveRecord::Base > acts_as_dropdown :text => "nom" > end > > <%= select(''recipes'', ''category_id'', Category.to_dropdown) %>ok thanks u -- Bolo Michelin Blog [Flash & RoR] http://blog.developpez.com/?blog=30 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060425/6adba4ec/attachment.html