Class: Admin::SmsOnRails::OutboundsController
- Inherits:
-
BaseController
- Object
- BaseController
- Admin::SmsOnRails::OutboundsController
- Defined in:
- app/controllers/admin/sms_on_rails/outbounds_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /admin/sms/outbounds POST /admin/sms/outbounds.xml.
- #deliver_sms(success_message = nil) ⇒ Object
-
#destroy ⇒ Object
DELETE /admin/sms/outbounds/1 DELETE /admin/sms/outbounds/1.xml.
-
#edit ⇒ Object
GET /admin/sms/outbounds/1/edit.
-
#index ⇒ Object
GET /admin/sms/outbounds GET /admin/sms/outbounds.xml.
-
#new ⇒ Object
GET /admin/sms/outbounds/new GET /admin/sms/outbounds/new.xml.
-
#show ⇒ Object
GET /admin/sms/outbounds/1 GET /admin/sms/outbounds/1.xml.
-
#update ⇒ Object
PUT /admin/sms/outbounds/1 PUT /admin/sms/outbounds/1.xml.
Instance Method Details
#create ⇒ Object
POST /admin/sms/outbounds POST /admin/sms/outbounds.xml
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/admin/sms_on_rails/outbounds_controller.rb', line 47 def create @draft = SmsOnRails::Draft.find(params[:sms_draft_id]) if params[:sms_draft_id] @outbound = SmsOnRails::Outbound.create_with_phone(params[:outbound], @draft) respond_to do |format| unless @outbound.errors.any? flash[:notice] = 'Outbound was successfully created.' format.html { redirect_to(sms_draft_outbound_path(@draft, @outbound))} format.xml { render :xml => @outbound, :status => :created, :location => @outbound } else # evil hack as forms are rejected with an id value @outbound.phone_number.id = nil if @outbound.phone_number format.html { render :action => "new" } format.xml { render :xml => @outbound.errors, :status => :unprocessable_entity } end end end |
#deliver_sms(success_message = nil) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/controllers/admin/sms_on_rails/outbounds_controller.rb', line 104 def deliver_sms( = nil) @outbound ||= SmsOnRails::Outbound.find(params[:id]) respond_to do |format| if @outbound.deliver(:fatal_exception => nil) flash[:notice] = || 'Outbound SMS was successfully sent' format.html { redirect_to(sms_draft_outbound_path(@outbound)) } format.xml { head :ok } else format.html { render :action => :edit } format.xml { render :xml => @outbound.errors, :status => :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /admin/sms/outbounds/1 DELETE /admin/sms/outbounds/1.xml
93 94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/admin/sms_on_rails/outbounds_controller.rb', line 93 def destroy @outbound = SmsOnRails::Outbound.find(params[:id]) @draft = @outbound.draft @outbound.destroy respond_to do |format| format.html { redirect_to(sms_draft_outbounds_url(@draft)) } format.xml { head :ok } end end |
#edit ⇒ Object
GET /admin/sms/outbounds/1/edit
41 42 43 |
# File 'app/controllers/admin/sms_on_rails/outbounds_controller.rb', line 41 def edit @outbound = SmsOnRails::Outbound.find(params[:id]) end |
#index ⇒ Object
GET /admin/sms/outbounds GET /admin/sms/outbounds.xml
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/controllers/admin/sms_on_rails/outbounds_controller.rb', line 4 def index if params[:sms_draft_id] @draft = SmsOnRails::Draft.find( params[:sms_draft_id], :include => :outbounds ) @outbounds = @draft.outbounds end @outbounds ||= SmsOnRails::Outbound.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @outbounds } end end |
#new ⇒ Object
GET /admin/sms/outbounds/new GET /admin/sms/outbounds/new.xml
31 32 33 34 35 36 37 38 |
# File 'app/controllers/admin/sms_on_rails/outbounds_controller.rb', line 31 def new @outbound = SmsOnRails::Outbound.new(:sms_draft_id => params[:sms_draft_id]) respond_to do |format| format.html # new.html.erb format.xml { render :xml => @outbound } end end |
#show ⇒ Object
GET /admin/sms/outbounds/1 GET /admin/sms/outbounds/1.xml
20 21 22 23 24 25 26 27 |
# File 'app/controllers/admin/sms_on_rails/outbounds_controller.rb', line 20 def show @outbound = SmsOnRails::Outbound.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @outbound } end end |
#update ⇒ Object
PUT /admin/sms/outbounds/1 PUT /admin/sms/outbounds/1.xml
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/admin/sms_on_rails/outbounds_controller.rb', line 68 def update @outbound = SmsOnRails::Outbound.find(params[:id]) if params[:outbound] @outbound.update_attributes(params[:outbound]) end if @outbound.errors.blank? && params[:send_immediately] deliver_sms('Outbound message was updated and sent.') end respond_to do |format| unless @outbound.errors.any? flash[:notice] = 'Outbound was successfully updated.' format.html { redirect_to(sms_draft_outbound_path(@outbound.draft, @outbound)) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @outbound.errors, :status => :unprocessable_entity } end end end |