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

12,426

The trick is using the input_html option.

= f.input :entity_name, input_html: { name: 'entity[name]' } 
Share:
12,426
sixty4bit
Author by

sixty4bit

Updated on June 16, 2022

Comments

  • sixty4bit
    sixty4bit almost 2 years

    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!