- Organize controllers using a module.
- Use namespaced routes.
We're going to add some administrative functions to our song library.
Using what we learned about namespaced routes and module scope, we'll
organize our controllers and routes under an admin
namespace to keep
them separate from the regular user functions.
The base application has been provided with tests. Make sure to run
rake db:seed
to set up seed data. Tests can be run with rspec
.
Note: Since we're building new features on an existing project that already has tests, part of the job is to make sure the tests that already pass at the beginning still pass when you're done!
- Create a migration and a model for a
Preference
class that will store preferences for the app. In the migration, defineboolean
fields for:allow_create_songs
: Allows for creation of new songs. Used to control the ability to add new songs to the system.allow_create_artists
: Allows for creation of new artists. Used to control the ability to add new artists to the system.- Note: There will only be 1 instance of
Preference
, not a preference associated with each artist/song. After creating the model, runrake preferences:load
so that your code will work in the browser. This will run the Rake task defined in thelib/tasks/preferences.rake
file and save onePreference
instance to the database.
- Create a
PreferencesController
, routes, and views. Do this under anAdmin
module to separate it from the standard user functionality. - Update the
songs#new
andartists#new
actions to check that creating new songs or artists is enabled using thePreference
class, and redirect to/songs
and/artists
, respectively, if that preference is disabled. If the preference is enabled, show thenew
view instead.- Hint: Remember, there will only be one instance of the
Preference
class saved to the database. When determining if creating songs or artists is enabled, you'll need to find the first instance of thePreference
class, and use that instance along with some conditional logic to determine whether to redirect or display the view.
- Hint: Remember, there will only be one instance of the
- Make sure tests pass.