开发者

Pre-checking collection of model objects used as check boxes with Formtastic

So I've got some objects that I'm passing as a collection:

@things = Thing.all

And in my view:

<%= f.input :things, :collection => @things, :as => :check_boxes %>
开发者_开发百科

Is there any way to specify which of the objects should already be checked when the view is loaded?

Thanks!


In your controller's "new" action, you want to initialise the form object with the values you want by default:

def new
  @post = Post.new
  @post.things = [@one_thing, @another_thing]
end

This can also be done as an after_initialize hook in the model itself.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜