sms-pager/app/controllers/pages_controller.rb

31 lines
633 B
Ruby
Raw Normal View History

2015-09-12 15:37:05 -05:00
class PagesController < ApplicationController
2015-09-20 13:26:45 -05:00
def index
@pages = Page.last_ten
respond_with @pages
end
2015-09-20 22:30:44 -05:00
def page
@page = Page.new
2015-09-21 20:40:07 -05:00
person = Person.find_by(id: params[:id])
2015-09-20 22:30:44 -05:00
@people = Person.pageable
return if person.nil?
@page.person_id = person.id
@page.to = person.phone
end
2015-09-20 13:26:45 -05:00
def send_page
2015-09-21 20:40:07 -05:00
page = Page.create page_params.merge(status: 'sent')
sms = ::SmsSender.new(to: page.to, message: page.message)
sms.send!
redirect_to list_pages_path, notice: "Page sent!"
2015-09-20 13:26:45 -05:00
end
2015-09-21 20:40:07 -05:00
private
def page_params
params.require(:page).permit(:message, :to, :person_id)
end
2015-09-12 15:37:05 -05:00
end