In rails 4.2, I am using paginate
method to get paginated records from db. I want to get first page, if specified page is not present in the db.
I am using following active record functionality to fetch paged records from database. So If the page number is mentioned 2
and there is only one row in db, the query returns null.
@records = @user.where("some where clause here").paginate(per_page: 1, page: params[:page].presence || 1).
I want to fetch first record if specified page doesn't exist in db. It fetches first record, if params[:page] is empty, but if database doesn't have specified page, it returns nill.