我有一個模型「啓動」,我有另一個模型「Categorie」。這兩個表是關聯的。複選框的形式與Ruby on Rails中的模型相關聯
我想調用Categoria的數據到Startup的形式,這個類別顯示一個複選框。在窗體啓動窗體內我有categorie_id。這是密碼
<%= form_for(@startup) do |f| %>
<% if @startup.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@startup.errors.count, "error") %> prohibited this startup from being saved:</h2>
<ul>
<% @startup.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :description %><br />
<%= f.text_area :description %>
</div>
<div class="field">
<%= f.collection_select :round_id, Round.order(:name), :id, :name, include_blank: true %>
</div>
<div class="field">
<%= f.label :category %><br />
<%= f.text_field :category_id %>
</div>
<div class="field">
<%= f.collection_select :country_id, Country.order(:name), :id, :name, include_blank: true %>
</div>
<div class="actions">
<%= f.submit %> </div> <% end %>
如何使用複選框在表單中顯示類別數據?
任何想法。
pdt:我的英語非常糟糕。
你想顯示所有可用的類別旁邊有一個複選框,當你提交表單時,它保存'@ startup'與類別關聯? (如果你願意,我可以用法語) – MrYoshiji
是的,我需要它(我會說西班牙語)。任何想法我該怎麼做? –
好的首先要知道:一個Startup可以有多個分類嗎? (有沒有在模型啓動'has_many:categories'或'belongs_to:category'中設置?第二個問題,你需要複選框還是下拉菜單(帶有Categories選項的html選擇)? – MrYoshiji