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
On Thu, May 22, 2008 at 3:19 PM, Sean S.
[email protected]
wrote:
Well, I added will_paginate to my application. Though when I attempt to
use I get an action controller error.
The message is:
NoMethodError in CommunityController#index
undefined method `paginate’ for #CommunityController:0xb6bd4ba4
Did you restart your server?
Brandon
Kieran P wrote:
Hello,
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 S.
[email protected]
When I change that it throws the error:
NameError in CommunityController#index
undefined local variable or method `spec’ for
#CommunityController:0xb6b0d504
Hello,
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 S.
[email protected]
Rails T. wrote:
@pages, specs = paginate(:specs,
:conditions => ["last_name LIKE ?",
@initial+“%”],
:order => “last_name, first_name”)
@users = specs.collect { |spec| spec.user }
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]
Reinhart
http://teapoci.blogspot.com
I believe it is tied in with user.
This is the app/views/community/_user_table.rhtml file:
<% if @users and not @users.empty? %>
<% @users.each do |user| %>
<% end %>
<% if paginated? %>
<% end %>
Name | Age | Gender | Location |
<%= link_to user.name, profile_for(user) %>
|
<%= user.spec.age %> |
<%= user.spec.gender %> |
<%= user.spec.location %> |
Pages: <%= pagination_links(@pages, :params => params) %>
|
<% end %>
If that helps answer your question.
hmmm… now i understand what you want to do.
yes, of course your way is wrong. Try it :
@spec = Spec.find(:all, :conditions => [“last_name LIKE
?”,@initial+“%”], :order => “last_name, first_name”)
@user_collection = @spec.collect { |spec| spec.user }
@pages, @users = @user_collection.paginate :page => params[:page]
I read here:
This will_paginate support Array and Collection pagination or update
your pagination or copy those file to your
vendor\plugins\will_paginate\lib\will_paginate
or read it : devchix.com at Directnic
Reinhart
http://teapoci.blogspot.com
I have solution with regular pagination (not will_paginate)
@spec = Spec.find(:all, :conditions => [“last_name LIKE
?”,@initial+“%”], :order => “last_name, first_name”)
@user_collection = @spec.collect { |spec| spec.user }
@pages, @users = paginate_collection @user_collection, :page =>
@params[:page]
private
def paginate_collection(collection, options = {})
default_options = {:per_page => 10, :page => 1}
options = default_options.merge options
pages = Paginator.new self, collection.size, options[:per_page],
options[:page]
first = pages.current.offset
last = [first + options[:per_page], collection.size].min
slice = collection[first…last]
return [pages, slice]
end
Render From:
Good LUcK,
Reinhart
Did you sort out this problem?
I’ve got the same error message!
Regards
Daniel
@pages, specs = paginate(:specs,
:conditions => ["last_name LIKE ?",
@initial+“%”],
:order => “last_name, first_name”)
@users = specs.collect { |spec| spec.user }
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]
Reinhart
http://teapoci.blogspot.com