【问题标题】:Handle check box forms with an `:has_many :through` Record Association使用 `:has_many :through` 记录关联处理复选框表单
【发布时间】:2011-09-27 14:07:44
【问题描述】:

我正在使用 Ruby on Rails 3.0.7,我想在我的视图文件(即用于新表单和编辑表单)中使用带有 :has_many :through 记录关联的复选框字段。我看到使用has_and_belongs_to_many 记录关联轻松实现了那种东西,但是是否有可能轻松使用第一个提到的关联?如果有,该怎么做?

【问题讨论】:

标签: ruby-on-rails ruby ruby-on-rails-3 checkbox field


【解决方案1】:

Dogbert 提供的链接是手动操作的好方法。但是,如果您决定使用 Simple Form,您将获得该功能。

使用前面提到的文章中的示例,您可以这样做:

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

这个例子当然非常简单,但它应该可以工作。祝你好运!

【讨论】:

    猜你喜欢
    • 2015-05-16
    • 2011-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-17
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多