V.J.
V.J.

Reputation: 9580

How to add options in select in ROR.?

I am trying to add options in the select field. but it will not work as i m expected.

Below i post my code. Please help to solve this one.

<select id='address_select' name='address_select' style="width: 100%; border-radius: 9px 9px 0 0; padding-top: 6px;">
  <% OrganizationSettings.getInstance().fetch() %>
  <% @addresses = OrganizationSettings.getInstance().valueForField('addresses') %>
  <option value="123" selected="selected">Facility</option> 
  <% for address in @addresses: %>
    <% @val = address.label %>
    <option value='<% address.id %>'> <% @val %> </option> 
  <% end %>
</select>

Here, in @addresses i m getting the value of the address class. I am getting the answer with <% alert(address.label) %> but when i pass the same value in the option it will not shown. It create the same number of options in the select but could not fill the value in the options.

Please help me.. Thanks in advance.

Upvotes: 0

Views: 67

Answers (1)

Wawa Loo
Wawa Loo

Reputation: 2276

You missed the =sign in <%= ... %>

<%= @val = address.label %>
<option value='<%= address.id %>'> <%= @val %> </option>

Upvotes: 1

Related Questions