开发者

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

I am using Ruby on Rails 3.0.7 and I would like to use check box fields in my view files (that is, for new and edit forms) with an :has_many :through Record Association. I seen that kind of things easily implemented using an has_and_belongs_to_many Record Association, but is it possible to make that to work easly with the first mentioned association? I开发者_Python百科f so, how to do that?


The link Dogbert supplied is a good way of doing it manual. If you however decide to use Simple Form you get that functionality build in.

Using the example from the previously mentioned article you would do:

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

This example is of course very simplified but it should work. Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜