[Rails] Re: Only get published items
I would take advantage of arel's method chaining and break down the
problem into smaller chunks. Instead of using true scopes, I'd create
some useful class methods like so:
class Song < ActiveRecord::Base
def self.published
where(:published => true)
end
def self.approved
where(:approved => true)
end
end
Then in your controllers, call the class methods to match whatever
special conditions you need on your song collection (or none at all
in, admin's case):
songs_controller:
@songs = Song.published.approved
admin_controller:
@songs = Song.all
Related reading:
http://www.railway.at/2010/03/09/named-scopes-are-dead/
http://elabs.se/blog/24-scopes-are-obsolete
--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home