13

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!

2 Answers 2

32

The trick is using the input_html option.

= f.input :entity_name, input_html: { name: 'entity[name]' } 
Sign up to request clarification or add additional context in comments.

Comments

-3

If you're looking to just change the shown label of the field:

= f.input :entity_name, label: 'new_input_field_name'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.