Creating an HTML select

Hi, I use the following code in a view to show a list of states inside a
form but I get not result, I mean I get no errors nor the expected HTML
code that should be something like <option …

@states = State.find(:all, :order => "name")
collection_select(:firm, :state_id, @states, :id, :name)

Can anyone please tell me why?

Are you wrapping the collection_select code in <%= %> tags?

Nik N. wrote:

Hi, I use the following code in a view to show a list of states inside a
form but I get not result, I mean I get no errors nor the expected HTML
code that should be something like <option …

@states = State.find(:all, :order => "name")
collection_select(:firm, :state_id, @states, :id, :name)

Can anyone please tell me why?


Sincerely,

William P.

http://www.billpratt.net
[email protected]

Hi William,
I’m a PHP developer and I’m testing RoR so I thought <% … %> was right
when writing more than one line of code! I just added “=” after “<%” and
it worked.
Thanks a lot! These are those little errors that can make you waste a
lot of time!
Nik

William P. wrote:

Are you wrapping the collection_select code in <%= %> tags?

Nik N. wrote:

Hi, I use the following code in a view to show a list of states inside a
form but I get not result, I mean I get no errors nor the expected HTML
code that should be something like <option …

@states = State.find(:all, :order => "name")
collection_select(:firm, :state_id, @states, :id, :name)

Can anyone please tell me why?


Sincerely,

William P.

http://www.billpratt.net
[email protected]

No problem. <% %> should be around code that you do not want the output
added to the rendered page (adding a dash at the end like -%> will
suppress the newline) and <%= %> goes around code that will generate
output to be included in the rendered page. Hope this helps you.

Nik N. wrote:

Are you wrapping the collection_select code in <%= %> tags?

Can anyone please tell me why?


Sincerely,

William P.

http://www.billpratt.net
[email protected]

Yes, very clear.
Thanks again.