Hi, I''ve got big problem. I was looking google for some info, but unfortunately, no solutions help me. So, my problem is: I''ve got this code: @pages, specs = paginate :specs, :conditions => ["last_name like ?", @initial+''%''], :order => "last_name, first_name", :per_page => 30 @users = specs.collect { |spec| spec.user } But it doesn''t work properly. I think: It is normal, because of new version of Rails (2.0 and higher), where paginate is plugin now. So i installed will_paginate by this way: gem install mislav-will_paginate (gem install will_paginate doesn''t work too!) And added on the end (after "end" word) in config/enviroment.rb: require ''will_paginate'' And at least I''m looking... Crash. Error like this: NoMethodError in CommunityController#index undefined method `paginate'' for #<CommunityController:0x49985b4> And now, I don''t know what to do. Any solutions?
On Aug 10, 7:07 pm, Kayne <m.bra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > undefined method `paginate'' for #<CommunityController:0x49985b4> > > And now, I don''t know what to do. Any solutions?Have you tried looking at the will_paginate examples at http://gitrdoc.com/mislav/will_paginate/tree/master/ ? Fred
Yes, but I didn''t understand this... I''m newb. I use now RailsSpace book. Will you so cool and translate to me: How can I change my code for will_paginate, please?
On Aug 10, 9:24 pm, Kayne <m.bra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yes, but I didn''t understand this... I''m newb. I use now RailsSpace > book. > Will you so cool and translate to me: How can I change my code for > will_paginate, please?It''s pretty simple. Your models gain a paginate method that is pretty much exactly the same as find (it takes the same options (:conditions, :order and so on) except that it also takes a :page and a :per_page option and loads only the relevant records. Fred
Ok, I make like this: @pages, specs = Spec.paginate :specs, :page => 30, :order => ''last_name, first_name'', :conditions => ["last_name like ?", @initial+''%''] And when I want to execute this code. browser gives me back: Couldn''t find Spec with ID=1 AND (last_name like ''B%'') I don''t know, what exactly it''s saying... I just want to paginate rows from model Spec (which one is belongs_to :user), to show users from databases. In Spec model I''ve got first_name and last_name and by ActiveRecord this is belong to User model. But now I''ve got problem - how it show by will_paginate?
RailsSpace is clearly outdated and that old "paginate" method should not be used anymore. You''re better served getting a newer book like the latest "Agile web development with Rails". - Maurício Linhares http://codeshooter.wordpress.com/ | http://twitter.com/mauriciojr On Mon, Aug 10, 2009 at 5:24 PM, Kayne<m.bratek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Yes, but I didn''t understand this... I''m newb. I use now RailsSpace > book. > Will you so cool and translate to me: How can I change my code for > will_paginate, please? > > >
On Aug 10, 9:50 pm, Kayne <m.bra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ok, I make like this: > > @pages, specs = Spec.paginate :specs, > :page => 30, > :order => ''last_name, first_name'', > :conditions => ["last_name like ?", @initial+''%''] > > And when I want to execute this code. browser gives me back: >Look at the will_paginate docs a little more closely. The paginate method returns a single object and (unlike the old paginate) you don''t pass it an argument to tell it what to paginate. That error message doesn''t look like something that will_paginate would raise though. Fred> Couldn''t find Spec with ID=1 AND (last_name like ''B%'') > > I don''t know, what exactly it''s saying... I just want to paginate rows > from model Spec (which one is belongs_to :user), to show users from > databases. In Spec model I''ve got first_name and last_name and by > ActiveRecord this is belong to User model. > > But now I''ve got problem - how it show by will_paginate?
Yeah, you right. But who will pay for it? ;) Ok, I made it. I''m go to... the next problem ;) I don''t know.. I hope you can help me. I''ve got that code: if params[:q] query = params[:q] # Najpierw wyniki spośród użytkowników... @users = User.find_with_ferret(query, :limit => :all) # ... a następnie podwyniki specs = Spec.find_with_ferret(query, :limit => :all) faqs = Faq.find_with_ferret(query, :limit => :all) # Teraz połącz w jedną listę oddzielnych użytkowników, posortowaną według nazwisk hits = specs + faqs @users.concat(hits.collect { |hit| hit.user}).uniq! # Sortuj wg. nazwiska (wymaga specyfikacji dla każdego użytkownika) @users.each { |user| user.spec ||= Spec.new } @users = @users.sort_by { |user| user.spec.last_name } end And here I have not any idea, how use will_paginate. Can you shot me a solutions?
On Aug 10, 10:36 pm, Kayne <m.bra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > And here I have not any idea, how use will_paginate. Can you shot me a > solutions?See http://www.pathf.com/blogs/2008/06/how-to-use-will_paginate-with-non-activerecord-collectionarray/ Fred
On Mon, Aug 10, 2009 at 11:07 AM, Kayne <m.bratek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > I''ve got big problem. I was looking google for some info, but > unfortunately, no solutions help me. > So, my problem is: > > I''ve got this code: > > @pages, specs = paginate :specs, > :conditions => ["last_name like ?", @initial+''%''], > :order => "last_name, first_name", > :per_page => 30 > @users = specs.collect { |spec| spec.user } > > But it doesn''t work properly. I think: It is normal, because of new > version of Rails (2.0 and higher), where paginate is plugin now. So i > installed will_paginate by this way: > > gem install mislav-will_paginate > > (gem install will_paginate doesn''t work too!) > > And added on the end (after "end" word) in config/enviroment.rb: > > require ''will_paginate'' > > And at least I''m looking... > > Crash. Error like this: > > NoMethodError in CommunityController#index > > undefined method `paginate'' for #<CommunityController:0x49985b4> > > And now, I don''t know what to do. Any solutions? >Kayne, you have a couple of choices: 1) Use the will_paginate gem here: http://github.com/mislav/will_paginate/tree/master and follow the notes here: http://blog.railsspace.com/past/2008/1/31/railsspace_will_paginate/ 2) Use the class_pagination plugin here: http://github.com/masterkain/classic_pagination/tree/master Personally, I would recommend option (1) being that it works better for moving search functionality into the model. Good luck, -Conrad> > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---