So I’m runnning rails 3.1.0.rc6 and I’m having a hard time understanding drop downs (select elements) with models.
I have the following:
<%= form_for @user do |f| %>
<div class="input">
<%= f.label :email %>
<%= f.text_field :email %>
</div>
<div class="input">
<%= f.label :password %>
<%= f.password_field :password %>
</div>
<div class="input">
<%= f.label :password_confirmation, "Repeat Password" %>
<%= f.password_field :password_confirmation %>
</div>
<div class="input">
<%= f.label :first_name %>
<%= f.password_field :first_name %>
</div>
<div class="input">
<%= f.label :last_name %>
<%= f.password_field :last_name %>
</div>
<div class="input">
<%= f.label :birthday %>
<%= date_select "user", "birthday" %>
</div>
<div class="input">
<%= f.label :gender %>
<%= select_tag :gender, options_for_select([['Male', 'male'], ['Female', 'female']]) %>
</div>
<div class="submit">
<%= f.submit nil, :class => ['button', 'button_blue'] %>
</div>
<% end %>
Now I don’t understand how to have an easy to use birthday select and gender select. The HTML it generates is not exactly friendly to use with model saves.
Any help would be great! Thanks.
Goal: Just be able to do an easy User.create with the posted data.
You can use the select form builder helper directly off your ‘f’ variable as such
This will make sure that the name and id for the select is generated in such a manner that your create will pick it up automatically.