[英]JQuery/Rails: How to render a partial with params?
In a rails 4.2 app, I would like to render a partial form _form_list.html.erb
with a params whs_id
. 在Rails 4.2的应用程序,我想呈现局部形式_form_list.html.erb
与PARAMS whs_id
。 Here is our code in index.js.erb
: 这是我们在index.js.erb
的代码:
$('#index_page').html('<%= escape_javascript render(:partial => "form_list.html.erb?whs_id=#{params[:whs_id]}") %>');
In debugger, the index
action is not launched. 在调试器中,不会启动index
操作。 I did a test with: 我做了一个测试:
$('#index_page').html('This is a test');
The index page is wiped out and replaced with This is a test
. 索引页被清除,并替换为“ This is a test
。
What's the right way to render a partial with a params in jquery? 在jquery中用参数渲染部分的正确方法是什么?
Rendering partials with params
is not possible. 无法使用params
渲染局部。 I think, you want to pass some local variable into the partial. 我想,您想将局部变量传递给局部变量。
Passing locals can be achieved - 通过当地人可以实现-
$('#index_page').html("<%= j render partial: 'form', locals: {whs_id: params[:whs_id]} %>");
Hope, that helps! 希望有帮助!
Try: 尝试:
... render 'form_list', locals: { whs_id: @whs_id } ...
Where 哪里
@whs_id = params[:whs_id]
and is set in your controller action because params is a controller method. @whs_id = params[:whs_id]
并在您的控制器操作中设置,因为params是控制器方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.