问题
I want to use simple_form_for to display a form that contains inputs for creating an instance of model A and separately an instance of model B. I want to have a single submit button for the form. Models A and B are not associated in any way, so simple_fields_for doesn't seem to apply here. Ideally, params would contain two hashes, under the keys A and B, so that each object's fields are grouped together. Is there a way to achieve this using simple_form? Thanks.
回答1:
You could use fields_for helper:
= form_tag action_path do
= fields_for :model_a do |a|
= a.text_field :name
= fields_for :model_b do |b|
= b.text_field :name
= submit_tag 'Submit'
来源:https://stackoverflow.com/questions/23622709/rails-a-single-simple-form-with-two-unrelated-models