我有一个我不理解的行为。
点击一个简单的link_to :remote=>true
向导/index.html.erb
< %= link_to "bros", new_wizard_path(:idparent= >wz.idparent, :id= >wz.id), :remote => true %>
控制器准备一个新的@wizard 实例
控制器/wizards_controller.rb
def new
@wizard = Wizard.new
@wizard.idparent = flash[:id_of_parent]
flash[:id_of_parent] = nil
@wizard.idparent ||= params[:idparent]
end
然后调用对应的js.erb,
向导/new.js.erb
$('#divwizard').append('<div id="wizardnew"></div>');
$('#wizardnew').html('<%=j (render(:partial => "wizards/new")) %>');
后者称为局部视图
向导/_new.html.erb
< %= render :partial = > "wizards/form" % >
向导/_form.html.erb
<%= form_for @wizard, :remote => true do |wiz| %>
< div class="edt_wiz" >
< div class="edt_wiz_pos" >
<%= wiz.label :pos, :class => "pos"%>
<%= wiz.text_field :pos %>
但是在 webrick 日志上,我在 *_new.html.erb* 上读到了一个双重电话
网砖日志
Started GET "/wizards/new?id=126" for 127.0.0.1 at 2013-10-21 19:08:51 +0200
Processing by WizardsController#new as JS
Parameters: {"id"=>"126"}
Rendered wizards/_form.html.erb (5.7ms)
Rendered wizards/_new.html.erb (6.9ms)
Rendered wizards/_form.html.erb (6.3ms)
Rendered wizards/_new.html.erb (7.1ms)
Rendered wizards/new.js.erb (17.7ms)
Completed 200 OK in 79ms (Views: 28.0ms | ActiveRecord: 0.9ms)
发生了什么 ?
谁调用 partial _new.html.erb 两次?
有人可以帮助我吗?我该如何调试这种情况?
编辑我
我省略了一段代码(对不起!)。
有一个javascript条件!:
新的.js.erb
if (something) {
$('#divwizard').append('<div id="wizardnew"></div>');
$('#wizardnew').html('<%=j (render(:partial => "wizards/new")) %>');
} else {
$('#otherdiv').append('<div id="wizard-other-new"></div>');
$('#wizard-other-new').html('<%=j (render(:partial => "wizards/new")) %>');
}
和erb,我认为(?),执行两个渲染:部分因为条件在javascript中,然后在浏览器上本地执行。
我很困惑还是正确的?