[Rails] Only get published items
Hi!
I'm new to Ruby and Rails and I'm trying it out with an app that
displays artists and their songs. The songs are nested inside the
artists.
Each song has a "published" and a "approved" attribute that is set to
true if the song has been approved and published.
I also have an admin area, mysite.com/admin/....
On the frontend I only want to show published and approved items and
in the admin area I want to show all songs.
I have created a scope in my model like this:
scope :frontend_songs, where(:approved => true, :published => true)
Which I want to apply on the frontend only. In my songs controller I
added a before_filter :front_songs
and
...
private
def front_songs
@songs = @songs.frontend_songs
end
This works good on pages that are not nested inside the artists (like
"latest songs")
So I have to do something similar for my Artist controller as well.
Is there a better way to do this so I only have to specify once that
songs that has published => false should not be served, regardless if
it comes through the artists or songs controller? Like a global scope
that always applies except in the admin area.
I have read somewhere about global scopes I think (??) but that you
should avoid them. Also, it would break my admin area as well.
So, any ideas?
--
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