1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
class CampaignsController < ApplicationController before_filter :load_campaign_or_redirect, :except => [:index, :sent, :new, :queued, :create, :processing] def index @campaigns = @current_user.campaigns.drafts end def sent @campaigns = @current_user.campaigns.sent end def new @campaign = Campaign.new end def create @campaign = Campaign.new(params[:campaign]) if @campaign.save redirect_to content_format_campaign_path(@campaign) else render :action => 'new' end end def edit; end def update respond_to do |format| if @campaign.update_attributes(params[:campaign]) flash[:notice] = 'Campaign has been updated.' format.html { redirect_to(@campaign) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @campaign.errors, :status => :unprocessable_entity } end end end def content_format; end def content_format_save if @campaign.update_attributes(params[:campaign]) if @campaign.format_of_campaign == 'html' redirect_to(html_source_campaign_path(@campaign)) elsif @campaign.format_of_campaign == 'text' redirect_to(text_content_campaign_path(@campaign)) end else render :action => 'content_format' end end def html_source; end def html_source_save if @campaign.update_attributes(params[:campaign]) if @campaign.content_injection_method == 'internet' redirect_to(import_url_campaign_path(@campaign)) elsif @campaign.content_injection_method == 'file' redirect_to(import_file_campaign_path(@campaign)) end else render :action => 'html_source' end end def import_file; end def import_file_save if @campaign.update_attributes(params[:campaign]) redirect_to(import_result_campaign_path(@campaign)) else render :action => 'import_file' end end def import_url; end def import_url_save @campaign.step = :step_import_url if @campaign.update_attributes(params[:campaign]) redirect_to(import_result_campaign_path(@campaign)) else render :action => 'import_url' end end def import_result; end def import_result_save if @campaign.update_attributes(params[:campaign]) render :action => 'import_result' else render :action => 'import_result' end end def text_content; end def text_content_save @campaign.step = :step_text_content if @campaign.update_attributes(params[:campaign]) redirect_to accept_content_campaign_path(@campaign) else render :action => 'text_content' end end def accept_content; end def recipients_source; end def recipients_source_save if @campaign.update_attributes(params[:campaign]) if @campaign.recipients_source == 'existing_list' redirect_to(select_lists_campaign_path(@campaign)) elsif @campaign.recipients_source == 'create_new_list' redirect_to(type_recipients_campaign_path(@campaign)) end else render :action => 'recipients_source' end end def type_recipients; end def type_recipients_save if @campaign.update_attributes(params[:campaign]) # some code for l8r else render :action => 'choose_recipients_source' end end def select_lists; end def select_lists_save if @campaign.update_attributes(params[:campaign]) redirect_to(recipients_import_result_campaign_path(@campaign)) else render :action => 'select_lists' end end def recipients_import_result; end def delivery_testing; end def send_test_email; end def schedule_delivery; end def schedule_delivery_save if @campaign.update_attributes(params[:campaign]) redirect_to(summary_campaign_path(@campaign)) else render :action => 'schedule_delivery' end end def summary; end def preview respond_to do |format| format.html { render :text => @campaign.body_html } format.text { render :text => @campaign.body_text } end end def show; end def processing if @current_user.campaigns.find(params[:id]).state != 'processing' redirect_to session[:return_path] end end private def load_campaign_or_redirect @campaign = @current_user.campaigns.find(params[:id]) if @campaign.state == 'processing' session[:return_path] = request.request_uri redirect_to processing_campaign_path(@campaign) end end end
Refactorings
No refactoring yet !
danielharan
April 28, 2008, April 28, 2008 21:01, permalink
That's no longer really restful. Instead of what appears to be a wizard on the front-end, consider loading the form all at once - maybe with javascript that shows each successive part of the form, or with tabbed controls. For the RESTful actions, you could use http://jamesgolick.com/resource_controller
Proably it's possible to cleanup this controller by define method, but i don't know how i can do this.