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> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, May 22, 2008 at 3:19 PM, Sean Six <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Six <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Six > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>When I change that it throws the error: NameError in CommunityController#index undefined local variable or method `spec'' for #<CommunityController:0xb6b0d504> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> @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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rails Terrorist 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.comI believe it is tied in with user. This is the app/views/community/_user_table.rhtml file: <% if @users and not @users.empty? %> <table class="users" border="0" cellpadding="5" cellspacing="1"> <tr class="header"> <th>Name</th> <th>Age</th> <th>Gender</th> <th>Location</th> </tr> <% @users.each do |user| %> <tr class="<%= cycle(''odd'', ''even'') %>"> <td><%= link_to user.name, profile_for(user) %> </td> <td><%= user.spec.age %></td> <td><%= user.spec.gender %></td> <td><%= user.spec.location %></td> </tr> <% end %> <% if paginated? %> <tr> <td colspan="4" align="right"> Pages: <%= pagination_links(@pages, :params => params) %> </td> </tr> <% end %> </table> <% end %> If that helps answer your question. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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: http://github.com/mislav/will_paginate/tree/master/lib/will_paginate 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 : http://www.devchix.com/2007/07/23/will_paginate-array/ Reinhart http://teapoci.blogspot.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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: http://teapoci.blogspot.com/2008/04/paginate-array-objects-in-ruby.html Good LUcK, Reinhart -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---