> model/comment.rb  --------------------------
>
> def self.between_profiles(profile1, profile2)
>     paginate(:all, {
>        :order => 'name',
>       :conditions => [
>         "(profile_id=? and commentable_id=?) or (profile_id=? and
> commentable_id=?) and commentable_type='Profile'",
>         profile1.id, profile2.id, profile2.id, profile1.id,'name
> like ?', "%#{search}%",]
>     }, :page => current_page || 1, :per_page => 3)
>   end
>
> controller/comments_controller.rb ---------------------------
>
> def index
>     @comments = Comment.between_profiles(@p, @profile)
>     redirect_to @p and return if @p == @profile
>     respond_to do |wants|
>       wants.html {render}
>       wants.rss {render :layout=>false}
>     end
>   end
>
> views/comments/index.html.erb -----------------------
>
>                 <%= will_paginate @comments %>
>
Ok.  you are trying to do too many things at once and therefore have
gotten in trouble.

Your goal should be to first:

1.  Make pagination work without any conditions.  You have a class
method defined at the model level so that is where the call to
pagination goes as I am showing above.  Once you do that, your
pagination functionality is encapsulated in the model class and
therefore you don't need to call it further again in the controller
code as I show above.  My suggestion would be to make it work without
the conditions first (or I would take out order clause as well).  Once
it starts to work, then;

2.  Move on to order and conditions but in small pieces, otherwise you
will never know what is wrong where.  I am not entirely sure if your
conditions are defined correctly, may be they are, but I will leave it
to you to debug that.

You need a good separation of concerns:  keep the model code where it
belongs and the controller code clean.  Whenever I am learning a new
functionality, e.g., will_paginate, I try to build from the simplest
case first and without mixing any other complications, once I begin to
understand fundamentally how it works, adding other functionality,
e.g., conditions, ordering, etc becomes incremental work.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Lovd by Less" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/lovdbyless?hl=en
Who loves ya baby?
-~----------~----~----~----~------~----~------~--~---

Reply via email to