kaminari paginate via ajax ,remote = true is not affect on view in rails 3

Ajay Barot picture Ajay Barot · Jun 24, 2014 · Viewed 7.4k times · Source

Hello i am using kaminari gem for pagination and i want to do paginatation via ajax .

index.html.haml

#abc
 = render :partial => 'anything/anything_lists', collection: @anything_upcoming, as: :anything_schedule
#paginator
 = paginate @anything_upcoming, :remote => true, :param_name => "anything_upcoming_page"

index.js.haml

$('#abc').html('#{escape_javascript render(partial: "anything/anything_lists")}');
$('#paginator').html('#{escape_javascript(paginate(@anything_upcoming, :remote => true, :param_name => "anything_upcoming_page").to_s)}');

controller file:

@anything_upcoming = AnythingSchedule.anything_upcoming.page(params[:anything_upcoming_page]).per(Settings.pagination.per_page)

respond_to do |format|
  format.js
  format.html
end

view source shows data-remote = true but log shows Website::EventsController#index as HTML. so what i am missing here.

Edit: i am doing some experiment on js file and i convert index.js.haml to index.js.erb and only one time i get ajax request and also shows calling JS on logs . and i redo again then as usual not get ajax request .

Final Edit application.js

//= require jquery
//= require jquery_ujs 
//= require ckeditor-jquery
//= require bootstrap.min
//= require bootstrap-datepicker.min
//= require bootstrap-timepicker.min
//= require chosen.jquery.min
//= require jquery.popupoverlay
//= require common
//= require ace-elements.min
//= require registrations
//= require courses
//= require instructors
//= require jsapi
//= require donation
//= require workshops
//= require nav_settings_dropdown
//= require events
//= require event_schedules
//= require manage_home
//= require jquery.blockUI
//= require rails

Gem file

gem 'rails', '3.2.17'
gem 'haml'
gem 'haml-rails'
gem "rails_config", "~> 0.3.3"

group :assets do
gem 'sass-rails',   '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'jquery-fileupload-rails'
gem 'jammit'
end

gem 'jquery-rails'
gem "kaminari", "~> 0.14.1"

Answer

Hardik picture Hardik · Jul 14, 2014

you must have forgotten to include the application.js in your layout file

OR

you are using another js or layout then the default one. Please check this

Reason:

The syntax for the pagination is correct

= paginate @anything_upcoming, :remote => true, :param_name => "anything_upcoming_page"

you have also included jquery-rails gem and also included the libraries in application.js

and you are saying data-remote = true is applying to the element. So the only problem I guess left is above one.