I have been working on this for few hours and got stuck, so
how to get menu selection using database, db using model ZigZagRotation?
<%= form_for([@user, @user.calories_journals.build]) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :cj_date, "Date Begins:" %>
<%= f.text_field :cj_date %>
<%= f.label :no_of_cycles, "Number of Cycles:" %>
<%= f.text_field :no_of_cycles %>
<%= f.label :zig_zag_type, "Zig Zag Rotation Type:" %>
<%= f.select :zig_zag_type, ZigZagRotation.all.collect {|z| [z.title, z.id ] } %>
<%= f.submit "Generate Calories Journals", class: "btn btn-large btn-primary" %>
<% end %>
The line below shows empty details in menu selection box instead of populated list.
<%= f.select :zig_zag_type, ZigZagRotation.all.collect {|z| [z.title, z.id ] } %>
:zig_zag_type is attr_accessible under ZigZagRotation model and once it is selected I wish the value to be stored in :id.
I am assuming that you are working with two different and related models (
ZigZagRotationandAnotherModelfor example).If you want to display the
zig_zag_typeattribute and save itsidin theAnotherModelforeign key (zig_zag_idfor example), creating the relationship between them, you can do something like the below:You can find more information here.
I hope it helps…