I have the following code which I'd like to render via javascript (Kaminari pagination via AJAX):
<div id="paginator-jobs-top" class="text-center">
<%= paginate @jobs, remote: true,
theme: 'twitter-bootstrap-3',
param_name: 'jobs',
params: { tab: 'jobs' },
pagination_class: 'pagination-small pagination-centered' %>
</div>
<div id="jobs">
<%= render partial: 'jobs/job_panel', collection: @jobs, as: :job %>
</div>
<div id="paginator-jobs-bottom" class="text-center">
<%= paginate @jobs, remote: true,
theme: 'twitter-bootstrap-3',
param_name: 'jobs',
params: { tab: 'jobs' },
pagination_class: 'pagination-small pagination-centered' %>
</div>
And I was trying with this js.erb code but its not working at all:
$('#paginator-jobs-top').html('<%= escape_javascript(paginate(@jobs,
remote: true,
theme: "twitter-bootstrap-3",
param_name: "jobs",
params: { tab: "jobs" },
pagination_class: "pagination-small pagination-centered").to_s) %>');
$('#jobs').html('<%= escape_javascript(render partial: "jobs/job_panel",
collection: @jobs,
as: :job) %>');
I tried other variations but none of them worked. If anyone knows how to render the above code in a js.erb method I'd love to hear!
The error I get from above is:
ArgumentError - wrong number of arguments (0 for 1)
When I try it with a slightly different line in the js.erb snippet (without ', job: j') I get:
NameError - undefined local variable or method `job' for #<#<Class:0x
**** Based on on Blelump's suggestion below I changed my code to this ***
<div id="jobs">
<%= render partial: "jobs/job_panel", collection: @jobs, as: :job %>
</div>
Which works great without AJAX (this is actually the correct way to render collection partials in Rails, my mistake before). However when I adjust the js.erb file to this I still get an error:
$('#jobs').html('<%= escape_javascript(render partial: "jobs/job_panel",
collection: @jobs,
as: :job) %>');
The error is from Kaminari again:
NoMethodError - undefined method `current_page' for nil:NilClass:
kaminari (0.16.1) lib/kaminari/helpers/action_view_extension.rb:18:in `paginate'