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 Sousa

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

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”)

Thanks Chirs, I will give it a try!

David Sousa

Chris Flipse wrote: