Topic: if statement in js.erb file based on param_name will_paginate (Ajax ca
I am trying to work out how to have multiple Ajax calls on the same page (same controller Action) using the will_paginate Gem. So far i have given each instance variable its own param_name so that they are not using the default param of :page
Example Controller
@meats= Recipe.meat_recipes.paginate(:page => params[:meat_recipes], :per_page => 1)
@vegrecipes = Recipe.veg_recipes.paginate(:page => params[:veg_recipes], :per_page => 1)
@desserts = Recipe.dessert_recipes.paginate(:page => params[:dessert_recipes], :per_page => 1)
Then in the view
<%= will_paginate @meats, :param_name => 'meat_recipes' %> (repeat this for individual instance variables)
So this part is fine. What i am doing is loading a partial when the AJAX request is made like so
.js.erb file
$('#meatRecipes').html('<%= escape_javascript(render partial: 'meatrecipes') %>');
$.setAjaxPagination();
so at the moment my meat instance variable is working fine. So how to conduct an if statement based on params?
I have tried this for example
<% if @meats %>
$('#meatRecipes').html('<%= escape_javascript(render partial: 'meatrecipes') %>');
$.setAjaxPagination();
<% end %>
<% if @vegrecipes %>
$('#vegRecipes').html('<%= escape_javascript(render partial: 'vegrecipes') %>');
$.setAjaxPagination();
<% end %>
Also tried
<% if @meats[:param_name] == 'meat_recipes' %>
$('#meatRecipes').html('<%= escape_javascript(render partial: 'meatrecipes') %>');
$.setAjaxPagination();
<% end %>
<% if @vegrecipes[:param_name == 'veg_recipes' %>
$('#vegRecipes').html('<%= escape_javascript(render partial: 'vegrecipes') %>');
$.setAjaxPagination();
<% end %>
but this doesn't work. So i guess my question is what do i use as my argument to ensure that the correct partial is being called for the particular pagination section.
Hope I have explained this correctly