I´m newbie in Ruby on rails, and I´m trying to display a select with the ids from an object b) in an object a):
Object a) Function
Object b) Experience
function _form.html.erb
<div class="field">
<%= f.label :experience_id %><br />
<%= f.number_field :experience_id %>
I want to create a select which display the items in the table experience. I suppose it’s a loop that loops through wich all elements of @ experience but not how. I have read about form helpers but I can not enlighten.
Thank so much
About Second Question
Thanks very much for your help. I tried like you proposed but the name of the select tag was not the correct name of the object and i don´t know how put it with that helper method. So i tried the same with another helper, select, and was success:
Option a)
select_tag :habilidad, options_for_select({“1” => 1, “2” => 2})
Resultant Source code:
<div class="field">
<label for="skill_habilidad">Habilidad</label><br />
<select id="habilidad" NAME="habilidad"><option value="1">1</option>
<option value="2">2</option></select>
</div>
Option b)
select(:skill, :habilidad, {“1” =>1, “2” => 2, “3” => 3, “4” => 4, “5” => 5})
Resultant source code:
<div class="field">
<label for="skill_habilidad">Habilidad</label><br />
<select id="skill_habilidad" NAME="skill[habilidad]"><option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option></select>
</div>
You could use
select_tagwithoptions_for_selectlike this:You can replace
(1..5).to_afor a variable.Reference: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-options_for_select