use*_*363 6 ruby-on-rails ruby-on-rails-3
有一种方法可以在js.erb中使用以下方式呈现erb页面:remote => true in rails:
$('#invoice_against_lease').html('$("<%= j render(:file => 'invoice/new.html.erb') %>")');
Run Code Online (Sandbox Code Playgroud)
我们有一个像这样的部分_customer_quote_record:
<%= f.input :quote_id, :label => 'Quote#?', :collection => quotes_for_invoice(@customer), :include_blank => true %>
<%= f.hidden_field :_destroy %>
Run Code Online (Sandbox Code Playgroud)
部分在html.erb中呈现为此,并传递局部变量构建器:
<%= f.simple_fields_for :invoice_items do |builder| %>
<%= render 'customer_quote_record', :f => builder %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
试过下面的代码:
$('#invoice_against_lease').html('$("<%= j render(:file => 'customer_lease_record', :f => f) %>")');
Run Code Online (Sandbox Code Playgroud)
错误是"ActionView::Template::Error (undefined local variable or method
f'......"`
有没有办法在js.erb中渲染上面的部分?
Nat*_*722 13
请尝试以下方法:
$('#invoice_against_lease').html('$("<%= j render(:partial => 'customer_lease_record', :locals => {:f => f}) %>")');
Run Code Online (Sandbox Code Playgroud)
当然,这假设f
在您进行此调用的任何位置都定义了该值.如果它不同,只需:locals => {:f => f}
改为:locals => {:f => "YOUR_VARIALBE"}
归档时间: |
|
查看次数: |
12942 次 |
最近记录: |