I'm getting errors on will_paginate such as: undefined method `paginate' for # in my rails app.
I'm trying to do the simplest possible query such as:
#results = Location.paginate(:page => params[:page])
or
#results = Location.paginate(:page => params[:page]).order('name')
Location.order('name') works fine in console
Any ideas what is going on or next steps? Does anything need to be added to the model?
Have you configured everything as outlined in the docs? I remember when I first got started with rails and will_paginate, I had to restart the web server for everything to work.
Related
I'm use will_paginate gem in my Rails application.
controller code:
def index
#posts = Guestbook.order('id DESC').page(params[:page]).per_page(10)
end
view code (used foundation gem):
<%= foundation_paginate #posts %>
Everything works fine, but if you type in the address bar room for a page, a blank page is displayed (no error messages or redirect to the first page). Tell me how to fix it, please.
P.S. I'm sorry for my bad english
you have to set will_paginate to use an array.
In config/initializers/
create a new file called will_paginate_extensions.rb
and add this:
require 'will_paginate/array'
I also would recommend not to use that foundation gem you are using for will_paginate, It can't receive parameters. I ran into that problem with that gem so i made one that can receive parameters
https://github.com/acrogenesis/will_paginate-foundation
I am using active_admin to generate an admin page on my rails app. I have had it for like a week, but suddenly today when I click the link emoticon which is a resource for the admin, I get this error :
NoMethodError in Admin::EmoticonsController#index
undefined method `per' for #
here is my emoticon controller :
def index
#emoticons = Emoticon.search(params[:search]).order(sort_column + ' ' + sort_direction).paginate(:per_page => 10, :page => params[:page])
end
I don't know, if I accidentally deleted one of active_admin file. But I recheck with the Railscast folder. And I think everything is fine. Anyone has any idea where the error could come from?
Please let me know if you need any other files.
Thanks.
Have you seen this? Assuming you are working with will_paginate.
So, I have a very simple bit of code that works great in Rails 2, but breaks in Rails 3.
In Rails 2 I have the following for displaying page contents using a viewer controller from the Page model:
class ViewerController < ApplicationController
show
#page = Page.find_by_name(params[:name])
end
My viewer show view has the following:
<%= #page.body %>
My routes.rb file has the following to handle this action:
map.view_page ":name", :controller => 'viewer', :action => 'show'
Here is the error I get in Rails 3 using this code:
undefined method `body' for nil:NilClass
Now, I know the routes have to be changed in Rails 3, but what else am I missing to make this simple code work in a Rails 3 app? I can't seem to find the answer anywhere. Thanks!
match ":name", :to => "viewer#show", :as => "view_page"
Not tested not sure if it's match "/:name" or if ":name" is ok too.
Ok, Rails 3 have got new routing sintax
get "/:name" => 'viewer#show'
Useful links:
http://railscasts.com/episodes/203-routing-in-rails-3
http://guides.rubyonrails.org/routing.html
http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/
UPD
Your error is because Rails can't find any Page with your :name:
There is no any Page with this name
There is no any :name at all in your params hash
Make sure your database has the body field filled with something and it should work just like you have it.
domain.com/viewer/show?name=home
Excuse me I have a problem with will_paginate plugin.
In localhost, in my controller, I use person.operations.descend_by_date.paginate :page => params[:page] || 1. However in production the method show error. I think that the problem is thye parameter page. Because person.operation.descend_by_date return a collection i try passing only params[:page] || 1.
However in localhost show error. The rare subject is:
If I evaluate the method once => Show error
IF i evaluate the method twice or more times => works ok
Rails show this message error: hash parameters expected
Why could be the error?
First i convert the will_paginate object to array and then i use the method for arrays of will_paginate
person.operations.descend_by_date.to_a.paginate params[:page] || 1
Thanks
I have a Rails 2.3.5 application and Im trying to render several Partials from within a Model (i know, i know -- im not supposed to). The reason im doing this is im integrating a Comet server (APE) into my Rails app and need to push updates out based on the Model's events (ex. after_create).
I have tried doing this:
ActionView::Base.new(Rails::Configuration.new.view_path).render(:partial => "pages/show", :locals => {:page => self})
Which allows me to render simple partials that don't user helpers, however if I try to user a link_to in my partial, i receive an error stating:
undefined method `url_for' for nil:NilClass
I've made sure that the object being passed into the "project_path(project)" is not nil. I've also tried including:
include ActionView::Helpers::UrlHelper
include ActionController::UrlWriter
in the Module that contains the method that makes the above "render" call.
Does anyone know how to work around this?
Thanks
We use the render_anywhere gem and have been happy with it.
From the README:
require 'render_anywhere'
class AnyClass
include RenderAnwhere
def build_html
html = render :template => 'normal/template/reference',
:layout => 'application'
html
end
end
Including these two modules should be enough. Maybe you forgot to set default_url_options[:host]? Without it you can use _path helpers, but not _url ones.
Include these modules and check out if it works in irb, maybe it will lead you to right solution.