Pagination not working with wice_grid Gem in Ruby on Rails

343 views Asked by At

I am working on Rails project and I am using "wice_grid" gem to create grids. It is throwing an error when I try to paginate the results:

undefined method `num_pages' for #<User::ActiveRecord_Relation:0x007f43b89a1610>

and here is my code:

In Controller

    def index
        @root_url="http://"+"#{request.env['HTTP_HOST']}";
        @users_grid = initialize_grid(User,:per_page => 20, :conditions => ['role= ?', "user"], :order => 'created_at',:order_direction => 'desc')
        @count=User.where(:role=>"user").count
        @record_per_page=20
        @total_record=@count/@record_per_page.ceil
    end

In View

<div class="widget-content" >
    <%= grid(@users_grid,:html=>{:class=>'table table-striped table-bordered',:id=>"tbl1"}) do |g| %>

        <% g.column  :name => 'FIRST NAME', :attribute => 'first_name',:html=>{:id=>"firstname"} do |user| %>
            <% content_tag(:td,:name => 'FIRST NAME', :attribute => 'first_name',onclick:"show(#{user.id});",:style=>"cursor:pointer") do %>
                <% user.first_name %>
           <% end %>
        <% end %>

        <% g.column  :name => 'LAST NAME', :attribute => 'last_name',:html=>{:id=>"lastname"} do |user| %>
           <% content_tag(:td,:name => 'LAST NAME', :attribute => 'last_name',onclick:"show(#{user.id});",:style=>"cursor:pointer") do %>
                <% user.last_name %>
           <% end %>
        <% end %>

    <% end %>
</div>

I have tried my best to fix this, but all in vain.

0

There are 0 answers