Javascript 在rails中使用Ajax时传递表单对象

Javascript 在rails中使用Ajax时传递表单对象,javascript,ruby-on-rails,ajax,forms,Javascript,Ruby On Rails,Ajax,Forms,我有一份复杂的调查表格。调查 belongs_to :template has_many :questions, :through => :template has_many :answers, :through => :questions 即,用户创建一个新调查,他必须选择一个调查模板。调查模板将创建一些默认问题和答案字段 <%= form_for @survey do |f| %> <p>Select a template:</p>

我有一份复杂的调查表格。调查

belongs_to :template
has_many :questions, :through => :template
has_many :answers, :through => :questions
即,用户创建一个新调查,他必须选择一个调查模板。调查模板将创建一些默认问题和答案字段

<%= form_for @survey do |f| %>

  <p>Select a template:</p>
  <%= render @templates, :locals => {:patient => @patient }, :f => f %>

<% end %>
调查新增:

new.js.erb:

新的测量路径:

但是我在将原始的| f |对象从@survey传递到新的| survey |路径时遇到了问题。我可以访问表单对象的最后一个位置是模板部分

我怎样才能解决这个问题

<% @templates.each do |template| %>

  <div class="thumbnail">
    <%= link_to template.name,
                { :controller => "surveys",
                  :action => "new",
                  :template_id => template.id,
                  :patient_id => nil,
                  :f => f,
                  :remote=> true },
                :class=> "template", :id=> template.id %>
  </div>

<% end %>
respond_to :js, :html

def new
  @template = Template.find(params[:template_id])
  @patient = Patient.find(params[:patient_id])
end
$('#assessment').append("<%= j (render new_survey_path, :locals => {:f => f} ) %>");
<%= f.fields_for :questions do |builder| %>
  <% @template.questions.where(category:"S").each do |question| %>
     <p><%= question.content %></p>
     <%= render 'answer_fields', :question=> question %>
  <% end %>
<% end %>