I have a rails project where users sign up and login. Users will create “Music” so I have a “Music” controller, the user will fill in a title, and upload their MP3. Every user can do this — this is dandy.
When a user logs in I want them to see everyone’s uploaded music in a nice list view at http://example.org/explore. I will have some “latest additions since your last login” somewhere on the sidebar of this “explore” page in the future among some other features.
My question is, should I create a controller called “Explore” with an index action for this listing with something like the following?
class ExploresController < ApplicationController
def index
@music = Music.all
end
def show
end
end
I thought this might be the right way to do this but it seems odd to have the “Explore” controller be using all of the actions you’d typically see in the “Music” controller. The Music controller is going to be CRUD for the current_user.
You can easily have the
music#indexmethod available to everyone and put user authentication on the CRUD methods. That way everyone can see all the uploaded music on the/musicpage, but only the owner of each one can alter them.If users need an easy way to see a list of use their own mp3s then you can just use a nested resource, so it would be available at
/users/:id/music.If you need some more info on how to implement that stuff then leave a comment. The specifics would depend on what (if any) authentication systems you were using.