user938363 user938363 - 3 months ago 15
jQuery Question

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
. Here is our code in
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. 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
.

What's the right way to render a partial with a params in jquery?

Answer

Rendering partials with params is not possible. 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!

Comments