rails/rails — pull request #4851 by carlosantoniodasilva (2012-02-02 13:04:40+00:00)
Title: Collection radio buttons / check boxes helpers

@rafaelfranca and I have been working to move SimpleForm's `collection_radio_buttons` and `collection_check_boxes` helpers to Rails. They work in a similar way to `collecion_select`, but generating a collection of radio_button/check_box + label for each item in the given collection. Here is an example usage:

```ruby
collection_check_boxes :post, :author_ids, Author.all, :id, :name
```

It'd output something like:

```html

D. Heinemeier Hansson

D. Thomas

```

It is possible to customize the output by giving a block to the helper. This block receives an argument, which is an "special builder" that is able to generate a label and radio_button/check_box for the given item context. For instance:

```ruby
collection_check_boxes(:post, :author_ids, Author.all, :id, :name) do |b|
b.label(:"data-value" => b.value) { b.check_box + b.text }
end
```

The helpers `label` and `check_box`/`radio_button` are available inside the block, scoped to the current element being rendered, that also accepts extra html options. The current `text` and `value` methods are also available for use, allowing better customization.

This PR also adds the ability for `collection_select` to receive proc values as `text_method` and `value_method`, something we've added to collection check_boxes/radio_buttons/select helpers in SimpleForm.

Thanks.