Conditional named_scope chaining with params (Need help)

Hello there,

I have a model that has more then one named_scope.

In my action Index of the controller that handle this model I want to do
this in a drier way:

if params[:ownership] == "mine"
    @posts = Post.tagged_with(params[:tags], :on =>

:tags).owner(current_user.id).paginate :all, :page => params[:page],
:order => ‘created_at DESC’
else
@posts = Post.tagged_with(params[:tags], :on => :tags).paginate
:all, :page => params[:page], :order => ‘created_at DESC’
end

This is just a example, I have a lot of options that is why I don’t want
to use the if else end structure.

Thanks,

David S.

On Tue, Jan 5, 2010 at 8:04 AM, David S. [email protected]
wrote:

:order => ‘created_at DESC’
else
@posts = Post.tagged_with(params[:tags], :on => :tags).paginate
:all, :page => params[:page], :order => ‘created_at DESC’
end

chain = Posts.tagged_with(params[:tags], :on => :tags)
chain = chain.owner(current_user.id) if params[:owner]
chain = chain.posted_since(params[:since]) if params[:since]

@posts = chain.paginate(:page => params[:page], :order => “created_at
DESC”)


// anything worth taking seriously is worth making fun of
// http://blog.devcaffeine.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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.

Thanks Chirs, I will give it a try!

David S.

Chris F. wrote:

chain = Posts.tagged_with(params[:tags], :on => :tags)
chain = chain.owner(current_user.id) if params[:owner]
chain = chain.posted_since(params[:since]) if params[:since]

@posts = chain.paginate(:page => params[:page], :order => “created_at
DESC”)