From 70813eb730702c29037e26193b84abd49cebd931 Mon Sep 17 00:00:00 2001 From: Matt Moriarity Date: Sat, 4 Aug 2007 16:24:12 -0400 Subject: [PATCH] ShowsController is now made_resourceful and documented. --- app/controllers/shows_controller.rb | 101 ++++++++++++++++-------------------- app/controllers/songs_controller.rb | 21 ++++---- 2 files changed, 56 insertions(+), 66 deletions(-) rewrite app/controllers/shows_controller.rb (74%) diff --git a/app/controllers/shows_controller.rb b/app/controllers/shows_controller.rb dissimilarity index 74% index 3a650a4..3a4bfb5 100644 --- a/app/controllers/shows_controller.rb +++ b/app/controllers/shows_controller.rb @@ -1,56 +1,45 @@ -class ShowsController < ApplicationController - in_place_edit_for :show, :title - - def index - respond_to do |wants| - wants.html { redirect_to home_url } - wants.xml { render :xml => current_user.shows.find(:all, :order => 'created_at DESC').to_xml } - end - end - - def create - show = current_user.shows.create params[:show] - - respond_to do |wants| - wants.html { redirect_to edit_show_path(show) } - wants.xml { render :xml => show.to_xml, :status => :created } - end - end - - def new - @show = current_user.shows.create(:title => 'Untitled') - - redirect_to edit_show_path(@show) - end - - def edit - @show = current_user.shows.find params[:id] - end - - def show - @show = current_user.shows.find params[:id] - - respond_to do |wants| - wants.html { render :layout => false } - wants.xml { render :xml => @show.to_xml(:include => :songs) } - end - end - - def destroy - @show = current_user.shows.delete current_user.shows.find(params[:id]) - - respond_to do |wants| - wants.html { redirect_to home_url } - wants.js - wants.xml { head :ok } - end - end - - def reorder - params[:songs_list].each_with_index do |id, idx| - Usage.update(id, :position => idx + 1) - end - - render :nothing => true - end -end +class ShowsController < ApplicationController + in_place_edit_for :show, :title + + make_resourceful do + # These are the only actions we need for now + actions :index, :show, :edit, :destroy + + # This URL should not be used + response_for(:index) { set_default_redirect home_path } + # The slideshow needs to use the S5 layout + response_for(:show) { render :layout => false } + # We want to avoid the index URL + response_for(:destroy) do + set_default_flash :notice, "The show was deleted." + set_default_redirect home_path + end + end + + # This behaves a little special + # + # See SongsController#new + def new + @show = current_model.create(:title => 'Untitled') + redirect_to edit_show_path(@show) + end + + # Assigns new positions to all the songs in + # the show. + # + # This should be called from an Ajax request. + def reorder + params[:songs_list].each_with_index do |id, idx| + Usage.update(id, :position => idx + 1) + end + render :nothing => true + end + + protected + # Make everything hang off the current user + # + # See SongsController#current_model + def current_model + current_user.shows + end +end diff --git a/app/controllers/songs_controller.rb b/app/controllers/songs_controller.rb index cc49b17..f419dfc 100644 --- a/app/controllers/songs_controller.rb +++ b/app/controllers/songs_controller.rb @@ -13,7 +13,7 @@ class SongsController < ApplicationController end # Easier to do multiple edits response_for(:update) do - set_default_flash :notice, "Save successful!" + set_default_flash :notice, "The song was saved." set_default_redirect edit_object_path end @@ -32,13 +32,14 @@ class SongsController < ApplicationController redirect_to edit_song_path(@song) end - # Make all songs hang off of the current user - # - # This serves two purposes: - # - Makes sure new songs belong to the current user - # - Makes sure the user can't access songs that belong - # to them - def current_model - current_user.songs - end + protected + # Make all songs hang off of the current user + # + # This serves two purposes: + # - Makes sure new songs belong to the current user + # - Makes sure the user can't access songs that belong + # to them + def current_model + current_user.songs + end end -- 2.11.4.GIT