3

嗨,我在我的应用程序中使用了多步表单

我在我的 form_for 标签中给出了渲染部分的链接。

我的html代码是,

<div class="carousel-inner">
    <%= form_for @subscribe , :validate => true, :html=>{:id=>"main_form"} do |f| %>
    <ul class='carosel_buttons inline'>
        <li class='circle active'>
            <h2><%= link_to "1", date_path, :remote => true %></h2>
        </li>
        <li class='circle'>
            <h2><%= link_to "2", booking_path, :remote => true %></h2>
        </li>
    </ul>
  <div class="item">
    <%= render "#{@subscribe.current_step}_step", :f => f %>
  </div>
</div>

我想使用 ajax 使用 link_to 标记在单击“1”时呈现部分日期。

现在我有我的控制器,

def date
  respond_to do |format|               
    format.js
  end
end

并具有相应的 date.js.erb 文件,

$('.item').html("<%= escape_javascript(render 'date_step', :f => f ) %>");

带有部分文件

<div class="field offset2" id="date">
  <%= f.label :date %><br />
  <%= f.hidden_field :start_date, :id=>"set_start_date" %>
  <%= f.hidden_field :end_date, :id=>"set_end_date" %>
  <div id='datepicker'> </div>
</div>

但是当我点击 1 时,

ActionView::Template::Error (#<#:0x007fb87ae09748> 的未定义局部变量或方法 `f'): 1: $('.item').html("<%= escape_javascript(render 'date_step', :f => f) %>");

我知道这是因为在我的 js.erb 文件中我无法链接:f=>f...

你能告诉我怎么做吗?

先感谢您。

4

1 回答 1

0

在您的 html 中,您正在使用 @subscribe 对象并将其传递给 f,但 f 没有在日期控制器的范围内定义,也没有在 date.js.erb 中定义。

我建议在部分(包含 form_for 助手)和控制器中(在日期函数中)呈现所有表单,您可以使用 Subscribe.new 设置 @subscribe 变量或使用参数查找它(Subscribe.find(params [:ID])

如果此解决方案对您不起作用,请告诉我!

于 2013-10-08T18:12:16.223 回答