user938363 user938363 - 1 year ago 134
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

with a params
. Here is our code in

$('#index_page').html('<%= escape_javascript render(:partial => "form_list.html.erb?whs_id=#{params[:whs_id]}") %>');

In debugger, the
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 Source

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!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download