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
--
Posted via http://www.ruby-forum.com/.
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
--
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 rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Sousa
Chris Flipse 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")
>