Select_tag

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

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

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’) %>

Thanks

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’) %>

Thanks

I 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

AN@S wrote:

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 K.