Module: SmsOnRails::CreationSupport

Included in:
Admin::SmsOnRails::DraftsController, SmsOnRailsController
Defined in:
app/controllers/sms_on_rails/creation_support.rb

Instance Method Summary collapse

Instance Method Details

#createObject



62
# File 'app/controllers/sms_on_rails/creation_support.rb', line 62

def create; create_sms_draft; end

#create_sms_draftObject

POST /admin/sms/drafts POST /admin/sms/drafts.xml



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
# File 'app/controllers/sms_on_rails/creation_support.rb', line 35

def create_sms_draft

  # Create a draft, send it immediately if the send_immediately param is set
  # and do not throw fatal delivery exception errors
  @draft = SmsOnRails::Draft.create_sms(params[:draft], nil,
    :send_immediately => params[:send_immediately],
    :deliver => {:fatal_exception => nil })

  respond_to do |format|
    unless @draft.errors.any?
      flash[:notice] = 'Draft was successfully created and sent.'
      format.html { render_sms_creation_success }
      format.xml  { render :xml => @draft, :status => :created, :location => @draft }
    else
      unless @draft.outbounds.any?
        setup_new_draft
      else
        #evil hack as when :id is set, the nested attributes updates don't work
        @draft.outbounds.each{|o| o.phone_number.id = nil if o.phone_number}
      end
      sanitize_draft_errors(@draft)
      format.html { render_send_sms_template }
      format.xml  { render :xml => @draft.errors, :status => :unprocessable_entity }
    end
  end
end

#editObject

GET /sms/1/edit



29
30
31
# File 'app/controllers/sms_on_rails/creation_support.rb', line 29

def edit
  @draft = SmsOnRails::Draft.find(params[:id])
end

#newObject

GET /sms/new GET /sms/new.xml



14
# File 'app/controllers/sms_on_rails/creation_support.rb', line 14

def new; send_sms; end

#send_smsObject



3
4
5
6
7
8
9
10
# File 'app/controllers/sms_on_rails/creation_support.rb', line 3

def send_sms
  setup_new_draft

  respond_to do |format|
    format.html { render_send_sms_template }
    format.xml  { render :xml => @draft }
  end
end

#showObject

GET /sms/1 GET /sms/1



19
20
21
22
23
24
25
26
# File 'app/controllers/sms_on_rails/creation_support.rb', line 19

def show
  @draft = SmsOnRails::Draft.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @draft }
  end
end