I have a array of arrays in my rails
application and it is something like:
@array=[[1, "Mr.X", "developer"], [2, "Mr.Y", "python"]...... [n, "Mr.Z", "ba"]]
I am getting these records on runtime from a different database server by using SQL
query not from ActiveRecord
. I want to perform pagination on this data and I am using will_paginate/array
@array = @array.paginate(:page => 1, :per_page => 1)
and in my view, I am calling it by:
<%= will_paginate @array%>
It is showing me the data of one record for the first page and links for other pages, however when clicked on next page link, it is giving the error for nil:nil class
, as it is again submitting the parameters but this time, the parameters are not appropriate.
I have the final records in @array and I don't want to send the request in backend again and again and I just want to process it on front end only.
Thanks in advance.
Note: I am having different issue, while submitting the form on the post method for first time, my params are
params = <ActionController::Parameters {"utf8"=>"✓", "authenticity_token"=>"EEzvZTAdFAGZ1vOvfeQ/hx7BmDFknC+xHpP4HdhIUncfZDobL1le1vzeanLRdgVFQtKYLGPCgKOfqf5J9+4J2Q==", "check_box_array"=>["ID", "NAME", "ROLE"], "column_value"=>{"ID"=>"", "NAME"=>"", "ROLE"=>""}, "table_name"=>"employee", "column_length"=>"3", "commit"=>"Search", "controller"=>"test", "action"=>"index"}
and here on the controller index action I am running SQL query and fetching data from database not using any model and storing the results into array, which I am passing to view like ` <%= will_paginate @array %>
But while clicking on any page number, it is submitting the parameters as <ActionController::Parameters {"page"=>"2", "controller"=>"test", "action"=>"index"} permitted: false>
and this time, it is not having any query parameters and it is generating the error for nil class
undefined method for nil:NilClass
But I don't want to send the query parameters, I just want to show the data of @array
using pagination i.e. on every page just the required data.