I want to input selections and input it into micropost table. The selections is from categories table. It encounter problem of category column of micropost is blank so I suspect it cannot input data into the table micropost column of category. I search all the select, select_tag but cannot solve it… Is there anything I miss out?
<%= form_for @micropost do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<%= f.label :title %><br />
<%=h f.text_field :title %><br />
<%= f.label :content %><br />
<%=h f.text_area :content, :row => 30, :cols=> 30 %><br />
<% @category = Category.select("category").group("category")
cat = @category.map{|u| u.category}
%>
<%= select_tag :category, options_for_select(cat) %>
<%= f.submit "Post" %>
<% end %>
If you check your query you should see that parameter
categoryis sent separately frommicropostattributes becausegenerates field inside form with name
categorynotmicropost[category]to fix it you can use select instead