31 lines
633 B
Ruby
31 lines
633 B
Ruby
class PagesController < ApplicationController
|
|
def index
|
|
@pages = Page.last_ten
|
|
respond_with @pages
|
|
end
|
|
|
|
def page
|
|
@page = Page.new
|
|
person = Person.find_by(id: params[:id])
|
|
@people = Person.pageable
|
|
|
|
return if person.nil?
|
|
@page.person_id = person.id
|
|
@page.to = person.phone
|
|
end
|
|
|
|
def send_page
|
|
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!"
|
|
end
|
|
|
|
private
|
|
|
|
def page_params
|
|
params.require(:page).permit(:message, :to, :person_id)
|
|
end
|
|
end
|