Ruby on rails RubyonRails表单与

Ruby on rails RubyonRails表单与,ruby-on-rails,forms,relationship,has-many-through,simple-form,Ruby On Rails,Forms,Relationship,Has Many Through,Simple Form,我有一些用户在注册时需要回答一些问题。用户通过答案联接表有许多问题。我只是想弄清楚如何在用户的新操作上创建表单。我用的是简单的表格。以下是我的数据库模式: ActiveRecord::Schema.define(:version => 20120831144008) do create_table "answers", :force => true do |t| t.integer "user_id" t.integer "question_id"

我有一些用户在注册时需要回答一些问题。用户通过答案联接表有许多问题。我只是想弄清楚如何在用户的新操作上创建表单。我用的是简单的表格。以下是我的数据库模式:

ActiveRecord::Schema.define(:version => 20120831144008) do

  create_table "answers", :force => true do |t|
    t.integer  "user_id"
    t.integer  "question_id"
    t.text     "response"
    t.datetime "created_at",  :null => false
    t.datetime "updated_at",  :null => false
  end

  add_index "answers", ["user_id", "question_id"], :name => "index_answers_on_user_id_and_question_id"

  create_table "questions", :force => true do |t|
    t.string   "title"
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
  end

  create_table "users", :force => true do |t|
    t.string   "first_name"
    t.string   "last_name"
    t.datetime "created_at",      :null => false
    t.datetime "updated_at",      :null => false
  end

end
因此,在用户新页面上,我循环浏览问题标题,需要在每个问题下方创建一个文本区域并创建它。这是我到目前为止的表单,它不起作用,可能对解决方案没有多大帮助,但是

<%= simple_form_for(@user) do |f| %>
  <%= f.input :first_name %>
  <%= f.input :last_name %>
  <%= f.input :email %>
  <%= f.input :phone %>
  <%= f.input :organization %>
  <%= f.input :primary_contact %>
  <%= f.association :answers, collection: @questions %>
  <% @questions.each do |question| %>
    <div>
      <strong><%= question.title %></strong>
      <%= text_field_tag 'questions[]' %>
    </div>
  <% end %>
  <%= f.button :submit %>
<% end %>

我相信你需要做:

<%= simple_fields_for @questions.each do |question| %>


以确保获得嵌套的表单字段。

嘿,我不能很好地遵循此逻辑。我用一个有效的解决方案更新了我的问题,但可能不是最漂亮的。谢谢回复!
<%= simple_fields_for @questions.each do |question| %>