Well, I added will_paginate to my application. Though when I attempt to
use I get an action controller error.
here is the app/controller/community_controller file I created:
class CommunityController < ApplicationController
helper :profile
def index
@title = "Community"
@letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("")
if params[:id]
@initial = params[:id]
@pages, specs = paginate(:specs,
:conditions => ["last_name LIKE ?",
@initial+"%"],
:order => "last_name, first_name")
@users = specs.collect { |spec| spec.user }
end
end
def browse
end
def search
if params[:q]
query = params[:q]
# First find the user hits...
@users = User.find_by_contents(query, :limit => :all)
# ...then the subhits.
specs = Spec.find_by_contents(query, :limit => :all)
faqs = Faq.find_by_contents(query, :limit => :all)
# Now combine into one list of distinct users sorted by last name.
hits = specs + faqs
@users.concat(hits.collect { |hit| hit.user }).uniq!
# Sort by last name (requires a spec for each user).
@users.each { |user| user.spec ||= Spec.new }
@users = @users.sort_by { |user| user.spec.last_name }
end
end
end
The message is:
NoMethodError in CommunityController#index
undefined method `paginate' for #<CommunityController:0xb6bd4ba4>
I’m still new to Rails, but installed will_paginate yesterday with no problems. I believe pagination is a method from your model, not the controller. Thus
I'm still new to Rails, but installed will_paginate yesterday with no
problems. I believe pagination is a method from your model, not the
controller. Thus
@pages, specs = paginate(:specs,
should become
@pages, specs = Community.paginate(:specs,
or whatever the model is.
Hope this helps.
Regards
k776
On Fri, May 23, 2008 at 7:19 AM, Sean Six
<rails-mailing-list@andreas-s.net>
When I change that it throws the error:
NameError in CommunityController#index
undefined local variable or method `spec' for
#<CommunityController:0xb6b0d504>
It is confusing. because your 'specs' only can be accessed in controller
not in view. what is variable do you use for pagination? 'specs' or
'@users'?
Kieran P wrote:
@pages, specs = Community.paginate(:specs,
you can not use it because :specs is different table name than of
community.
@pages, @specs = Spec.paginate :conditions => ["last_name LIKE ?",
@initial+"%"], :order => "last_name, first_name", :page => params[:page]
It is confusing. because your 'specs' only can be accessed in controller
not in view. what is variable do you use for pagination? 'specs' or
'@users'?
Kieran P wrote:
@pages, specs = Community.paginate(:specs,
you can not use it because :specs is different table name than of
community.
@pages, @specs = Spec.paginate :conditions => ["last_name LIKE ?",
@initial+"%"], :order => "last_name, first_name", :page => params[:page]