问题
I'm using simple_form to create forms for same resource types, it works fine but I've one problem with the javascript due to the fact that all inputs have the same id.
For example, if my model is car and my field is brand, all the inputs for this field on al lteh forms have the same id car_brand
.
Is there a way to add a prefix to the id generated by simple_form inputs Without adding id to each input
回答1:
Pass your each form declaration a namespace
attribute like below to create uniqness.
<%= simple_form_for @user, namespace: 'first_user_form' do |f| %>
and
<%= simple_form_for @user, namespace: 'second_user_form' do |f| %>
'first_user_form'
and 'second_user_form'
can be any good names which explains your form purposes. I use them as an example.
来源:https://stackoverflow.com/questions/38191501/simple-form-multiple-forms-for-same-resource-type-on-page