簡體   English   中英

使用 `:has_many:through` 記錄關聯處理復選框 forms

[英]Handle check box forms with an `:has_many :through` Record Association

我在 Rails 3.0.7 上使用 Ruby,我想在我的視圖文件中使用復選框字段(即,用於新表單和編輯表單)和:has_many:through Record Association。 我看到這種事情容易使用has_and_belongs_to_many記錄關聯來實現,但是是否可以使用第一個提到的關聯輕松實現呢? 如果是這樣,該怎么做?

Dogbert 提供的鏈接是手動操作的好方法。 但是,如果您決定使用Simple Form ,您將獲得該功能。

使用前面提到的文章中的示例,您將執行以下操作:

<%= simple_form_for(@user) do |f| %>
  <%= f.association :groups, :as => :check_boxes %>
  <%= f.submit %>
<% end %>

這個例子當然非常簡化,但它應該可以工作。 祝你好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM