unknown action with will_paginate - ruby-on-rails

In my users controller I have this in a method:
#users = User.paginate :page => params[:page], :per_page => 10,
The results are rendered on users/search. The 2nd page link points to users/search?page=2, but it leads to an unknown action error.

Possibly there is something wrong in routes.rb, so you haven't got :search=>:get rout

Related

ruby : unsupported parameters: :order

I am able to install this app on my windows 7 laptop https://github.com/cheezy/puppies
But now when I am trying to access it at localhost:3000 it is giving me error:
unsupported parameters: :order
I went to the file in this app and found this code:
app/controllers/agency_controller.rb
class AgencyController < ApplicationController
skip_before_filter :authorize
def index
#puppies = Puppy.paginate :page => params[:page], :order => 'name', :per_page => 4
end
end
While looking for a fix on this error I found a fix here https://github.com/mislav/will_paginate/issues/500
Where a comment by "mislav" says that "Active Record doesn't support :xyz formatting and it need to be written in User.where(conditions).order('title').per_page(per_page).page(page) format.
So, if it is a fix how to write #puppies = Puppy.paginate :page => params[:page], :order => 'name', :per_page => 4 in suggested format?
But if its not actual fix how to fix it?
I think that's because you are passing :order into the paginate method.
The correct query should be:
#puppies = Puppy.order(:name).paginate(page: params[:page], per_page: 4)

Adding Ransack Gem with Categories

I am displaying a list of gyms, and users can view gyms by province. I would like to add search capability using the Ransack gem, but I am not sure how to go about it with my current set up. Looking for some advice.
Gyms controller
def index
if params[:province].blank?
#gyms=Gym.all.order("created_at desc").paginate(:page => params[:page], :per_page => 18)
else
#province_id = Province.find_by(name: params[:province]).id
#gyms = Gym.where(province_id: #province_id).order("created_at DESC").paginate(:page => params[:page], :per_page => 18)
end
end
thank you in advance.
Figured it out. Just replaced my existing controller code with this:
#q = Gym.ransack(params[:q])
#gyms = #q.result.includes(:province).page(params[:page]).order("created_at DESC").paginate(:page => params[:page], :per_page => 18)

Will paginate showing `RangeError`

I used will_paginate gem for pagination. This is my code:
def index
#templates = Template.all
#templates = Template.paginate(:page => params[:offset], :per_page => params[:limit])
end
Template has 52 records in database. When this action is executed, it shows an invalid page error. I don't understand the problem. Is there anyone to help me?

ActiveRecord Relation error

def index
#users = User.order("name").page(params[:page]).per_page(5)
end
This is my UsersController where i try to view all users from database. Problem is because is see only this error:
undefined method `page' for #<ActiveRecord::Relation::ActiveRecord_Relation_User:0x000000044853d8>
Where is the problem?
You can do like this incase you have used will_paginate gem
#users = User.order("name ASC").paginate(:page => params[:page], :per_page => 5)
Take a look on the gem will_paginate
The usage of will_paginate is slight different than Kaminari. You should do:
#users = User.order('name').paginate(page: params[:page], per_page: 5)

Ruby on Rails: will_paginate is not working correctly

If I click the next or previous link it doesn't go to the next or previous page.
All posts are on same page, but there are links next, previous at bottom.
In PostsController:
#posts = Post.paginate(:per_page => 15, :page => params[:page], :order => 'created_at DESC')
in posts/index:
<%= will_paginate #posts%>
Where is the problem with will_paginate?
You have to order before paginate,
so, change it to
#posts = Post.order('created_at DESC').paginate(:per_page => 15, :page => params[:page])
Not sure if this is causing your error, but ordering should be done outside of will_paginate.
#posts = Post.paginate(:per_page => 15, :page => params[:page]).order('created_at DESC')
This is how it should be done in Rails 3.
I've also had trouble setting the per_page parameter within the controller. You could try setting it in the model instead.
class Post
self.per_page = 10
end
Updating to will_paginate , '3.1.7' solved my issues

Resources