Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6753777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:12:08+00:00 2026-05-26T13:12:08+00:00

I am using plugin Kaminari for pagination. I am Ajaxifing my application and I

  • 0

I am using plugin Kaminari for pagination. I am Ajaxifing my application and I encountered a problem. I have a form with paginated data plus form for filtering data (both via Ajax). At start pagination works good, and the url’s for particular pages are ‘/admin/rooms?page=X’. After ajax filtering those url’s change for ‘/admin/rooms/filter?page=X’.
I can specify the action to trigger when paginating by:

<%= paginate @rooms, :params => {:controller => 'rooms', :action => 'index'}, :remote => true %>

but then variable @rooms gets resetted in index and I paginate unfiltered data again.

Any ideas how could I fix it?

Here’s some code

  • rooms_controller.rb:

    class Admin::RoomsController < AdminController
    def index
            @rooms = Room.all
            @rooms = Kaminari.paginate_array(@rooms).page(params[:page]).per(5)
            @filter_values = [['Room number', 'room_number'], ['Person count', 'person_count'], ['Room class', 'room_class']]
    end
    
    def filter
            case params[:filter_by]
            when 'room_number'
                    @rooms = Room.find(:all, :conditions => ["CAST(room_number AS VARCHAR) LIKE ?", "#{params[:filter_value]}%"])
            when 'person_count'
                    @rooms = Room.find(:all, :conditions => ["person_count LIKE ?", "#{params[:filter_value]}%"])
            else
                    @rooms = Room.joins(:room_class).where("lower(class_name) LIKE '#{params[:filter_value]}%'")
            end
    
            @rooms = Kaminari.paginate_array(@rooms).page(params[:page]).per(5)
            respond_to do |format|
                    format.html { redirect_to admin_rooms_path }
                    format.js
            end
    end
    
  • index.html.erb:

    <%= label_tag 'Filter:  ' %>
    <%= form_tag(filter_admin_rooms_path, :remote => true) do %>
            <%= select_tag :filter_by, options_for_select(@filter_values) %>
            <%= text_field_tag :filter_value %>
            <%= submit_tag 'Filter', :disable_with => 'Filtering..' %>
    <% end %>
    
    ...
    
    <div id="rooms_list">
            <%= render 'admin/rooms/shared/rooms_list' %>
    </div>
    
  • _rooms_list.html.erb:

    <div id="paginator">
            <%= paginate @rooms, :remote => true %>
    </div>
    <table class="table_listing" style="width: 60%">
            ...
    </table>
    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:12:08+00:00Added an answer on May 26, 2026 at 1:12 pm

    Problem solved by passing parameters again to index and forcing paginate to route to ‘rooms#index’, not the current page (not visible cause of Ajax though).

    • _rooms_list.html.erb:

      <%= paginate @rooms, :params => {:controller => 'rooms', :action => 'index'}, :remote => true %>
      

    Parametrs are passed to index by GET from the present params variable.

    • rooms_controller.rb:

      def index
              if params[:filter_value].nil?
                      @rooms = Room.all
              else
                      @rooms = test_filter(params[:filter_value])
              end
      
              @rooms = Kaminari.paginate_array(@rooms).page(params[:page]).per(5)
              @errors = flash[:errors] || []
              @filter_values = [['Room number', 'room_number'], ['Person count', 'person_count'], ['Room class', 'room_class']]
      end
      
      def filter
              case params[:filter_by]
              when 'room_number'
                      @rooms = Room.find(:all, :conditions => ["CAST(room_number AS VARCHAR) LIKE ?", "#{params[:filter_value]}%"])
              when 'person_count'
                      @rooms = Room.find(:all, :conditions => ["person_count LIKE ?", "#{params[:filter_value]}%"])
              else
                      @rooms = Room.joins(:room_class).where("lower(class_name) LIKE '#{params[:filter_value]}%'")
              end
      
              @rooms = Kaminari.paginate_array(@rooms).page(params[:page]).per(5)
              params[:authenticity_token] = nil
              params[:commit] = nil
      
              respond_to do |format|
                      format.html { redirect_to admin_rooms_path }
                      format.js
              end
      end
      
      def test_filter(val)
              rooms = Room.find(:all, :conditions => ["CAST(room_number AS VARCHAR) LIKE ?", "#{val}%"])
              rooms
      end
      

    test_filter is to remove/rename of course. I nil some parameter that I think shouldn’t be passed in params to the next page when paginate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jqxGrid plugin to display the data in a Grid. I have
I have an application that's suppose to be realized in plugin pattern. Plugins are
I am using autoNumeric plugin with the latest version of jQuery . I have
I am using this plugin: http://jquery.bassistance.de/autocomplete/demo/ I have an autocomplete textarea where the values
I using this plugin http://code.drewwilson.com/entry/autosuggest-jquery-plugin While typing MAS there is no data matched, so
I am using eGit plugin with eclipse. I have made changes to 7 files
I'm using a plugin called http://www.jigoshop.com with Wordpress (both the latest versions) and I'm
I'm using Syntastic plugin. I have some files with some errors (Warnings) that I
I am using JQuery plugin qtip for displaying tooltip in asp.net application. Here is
I am using the plugin jqModal which I have working just fine, however I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.