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

  • Home
  • SEARCH
  • 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 8844349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:27:53+00:00 2026-06-14T11:27:53+00:00

Ruby on Rails 3 project. After updating a record we return to the index

  • 0

Ruby on Rails 3 project. After updating a record we return to the index of all records (not a view of the updated record). The index is paged with Kaminari. How do we return to the page of the index that contains the updated record?

  • 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-06-14T11:27:54+00:00Added an answer on June 14, 2026 at 11:27 am

    There is a similar question and answer for Java JPA/Hibernate Finding out the page containing a given record using JPA (Hibernate) that shows the sql needed to get the offset of the record in the index view. Something like

    SELECT COUNT(*)
    FROM Model r
    WHERE r.column < ?
    ORDER BY r.id
    

    The page number will be offset/records_per_page + 1.

    The question then is how to get the records_per_page from Kaminari? Kaminari lets you set the number of records per page in configuration, and for a specific model through Model.paginates_per. It provides the Model.default_per_page method to yield number of records per page for the model.

    The best place to decide the page will be in the controller method that displays the index. That method already picks up the page param, if present, to display the correct page. Another way would be to compute the page before redirect and send the page param. Let’s try the former.

    After saving the edit we redirect to the index with a param identifying the record we want included in the index page redirect with params. The index sorts by Model.column.

    redirect_to model_index_url(:for_column => @model_record.column), 
       :notice => 'Record saved'
    

    Then in the index method of the controller we let the page param govern, or compute the page from the for_column param if present.

    page = 1 
    if (params[:page])
      page = params[:page]
    elsif (params[:for_column])
      offset = Model.select('count(*) as count').where('? < column',
         params[:for_column]).order(id).first
      page = offset.count/Model.default_per_page + 1
    end
    @records = Model.all.order('column desc').page(page)
    

    And of course, Model and Model.column stand for the model and column name for your application.

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

Sidebar

Related Questions

Hi I am working on ruby on rails project. after setting up all environment
This is not a ruby/rails project deploy. I have the following situation and I
In a my project in Ruby On Rails (but this is not important), when
after updating my ruby to 1.9.3 and rails to 3.2.3 I have been trying
I created a new Ruby on Rails 3.0.1 project, and then globally updated gems
I created a new Ruby on Rails 3.0.1 project, and then globally updated gems
I'm after an overview/clarification of the ideal project structure for a ruby (non-rails/merb/etc) project.
I am building a ruby on rails project. it is a portal. I have
I'm trying to build my Ruby on Rails project from github on Travis-CI, but
I am using Haml in a Ruby on Rails project. I know you use

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.