in my controller @cursos = Curso.find_all in my view i''m trying to do a select_tag with the results @cursos, using a helper select_tag "name" options_for_select(@cursos) --------> not works select_tag "name" @cursos --------> not works how to do it, using the helper? tks -- Posted via http://www.ruby-forum.com/.
Hello, I''m creating a form that contains a select_tag, I need to get options of that select tag pulled from a database table (I need to specify certain columns), how can this be done? Thanks in advance -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060723/7bce9f06/attachment.html
select_tag options_from_collection_for_select(collection, value_method, text_method, selected_value = nil) check it out on api.rubyonrails.com for more details; you could go like this: @people = Person.find(:all) <%= select_tag options_from_collection_for_select(@people, ''name'', ''id'', 3) %> # the checked value would be person number three hope it helps, s -- Posted via http://www.ruby-forum.com/.
shai wrote:> select_tag options_from_collection_for_select(collection, value_method, > text_method, selected_value = nil) > > check it out on api.rubyonrails.com > for more details; > > you could go like this: > @people = Person.find(:all) > > > <%= select_tag options_from_collection_for_select(@people, ''name'', ''id'', > 3) %> > # the checked value would be person number three > > hope it helps, > > sHello shai, I get a NoMethodError, here is my code #Model: @categories = Category.find(:all) #View: <%= select_tag options_from_collection_for_select(@categories, ''name'', ''id'') %> Thanks -- Posted via http://www.ruby-forum.com/.
AN@S wrote:> shai wrote: >> select_tag options_from_collection_for_select(collection, value_method, >> text_method, selected_value = nil) >> >> check it out on api.rubyonrails.com >> for more details; >> >> you could go like this: >> @people = Person.find(:all) >> >> >> <%= select_tag options_from_collection_for_select(@people, ''name'', ''id'', >> 3) %> >> # the checked value would be person number three >> >> hope it helps, >> >> s > > Hello shai, > > I get a NoMethodError, here is my code > > #Model: > > @categories = Category.find(:all) > > #View: > > <%= select_tag options_from_collection_for_select(@categories, ''name'', > ''id'') %> > > ThanksI use the acts_as_enumerated plugin for common "list of values". I believe the example below, however, should still work for you: <%= select (:order, :order_status, OrderStatus.all.collect {|s| [ (s.value), s.value ]}, { :include_blank => true }) %> Regards, Michael -- Posted via http://www.ruby-forum.com/.
AN@S wrote:> shai wrote: > >> select_tag options_from_collection_for_select(collection, value_method, >> text_method, selected_value = nil) >> >> check it out on api.rubyonrails.com >> for more details; >> >> you could go like this: >> @people = Person.find(:all) >> >> >> <%= select_tag options_from_collection_for_select(@people, ''name'', ''id'', >> 3) %> >> # the checked value would be person number three >> >> hope it helps, >> >> s >> > > Hello shai, > > I get a NoMethodError, here is my code > > #Model: > > @categories = Category.find(:all) > >No. It should be in the controller (in the action the view is run from), alternatively in the view itself (but that would be bad form) as <%- @categories = Category.find(:all) %> Regards, Henning Kilset
Fernando wrote:> in my controller > > @cursos = Curso.find_all > > in my view i''m trying to do a select_tag with the results @cursos, using > a helper > > select_tag "name" options_for_select(@cursos) --------> not works > select_tag "name" @cursos --------> not works > > how to do it, using the helper? > > tksMaybe you missed the commas? <%= select_tag("name", @cursos) %> should work. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---