Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4: Change 'name' attribute of Simple Form input

I am using Simple Form in a Rails 4 app for a @user object and have the line...

= f.input :entity_name

This generates the HTML name='user[entity_name]' inside the input tag. I would like to change it because of some custom processing I am doing in the controller but haven't found a way to do so.

I've tried changing the line to...

= f.input :entity_name, name: 'entity[name]'

...but this doesn't seem to affect the generated HTML at all. So far I haven't found anyone else with this question on Google/Stack Overflow.

Does anyone know if/how it's possible to change the name attribute through the Simple Form helper?

Thanks in advance!

like image 806
sixty4bit Avatar asked Jul 05 '15 01:07

sixty4bit


1 Answers

The trick is using the input_html option.

= f.input :entity_name, input_html: { name: 'entity[name]' } 
like image 60
max Avatar answered Sep 19 '22 08:09

max