rails/rails — Issue #5047: Setting html attributes not unified in form helpers
Author: jaroslawr
Created: 2012-02-15 11:34:48+00:00
State: open

Some form helpers allow directly setting html attributes:

```
# 1)
<%= link_to "Something", somethings_path, id: 'xyz', class: 'zyx' %>
```

Some require a html option:

```
# 2)
<%= form_for :something, html: {id: 'xyz', class: 'zyx'} do |f| %>
...
<% end %>
```

And some others require passing two hashes:

```
# 3)
<%= f.select(:attr, some_options, {}, {id: 'xyz', class: 'zyx'}) %>
```

So if you use the two in one form you get the following:

```
<%= form_for :something, html: {id: 'xyz', class: 'zyx'} do |f| %>
<%= f.select(:attr, some_options, {}, {id: 'xyz', class: 'zyx'}) %>
<% end %>
```

Is there any reason not to unify at least the forms 1) and 2) ? One could then instead write:

```
<%= form_for :something, html: {id: 'xyz', class: 'zyx'} do |f| %>
<%= f.select(:attr, some_options, html: {id: 'xyz', class: 'zyx'}) %>
<% end %>
```

This is much easier to remember, and can I guess be implemented without breaking compatibility. I can do the necessary changes and issue a pull request, if only such a change is accepted.

Unifying 1), 2) and 3) in a reasonable way is harder, but maybe someone has some ideas.