module RocketCMS::Controllers::Contacts

Public Instance Methods

create() click to toggle source
# File lib/rocket_cms/controllers/contacts.rb, line 15
def create
  @contact_message = model.new(message_params)
  after_initialize
  if RocketCMS.config.contacts_captcha
    meth = :save_with_captcha
  else
    meth = :save
  end
  if @contact_message.send(meth)
    after_create
    if request.xhr? && process_ajax
      ajax_success
    else
      redirect_after_done
    end
  else
    render_contacts_error
  end
end
index() click to toggle source
# File lib/rocket_cms/controllers/contacts.rb, line 5
def index
  @contact_message = ContactMessage.new
  after_initialize
end
new() click to toggle source
# File lib/rocket_cms/controllers/contacts.rb, line 10
def new
  @contact_message = model.new
  after_initialize
end
sent() click to toggle source
# File lib/rocket_cms/controllers/contacts.rb, line 35
def sent
end

Private Instance Methods

after_create() click to toggle source
# File lib/rocket_cms/controllers/contacts.rb, line 59
def after_create
  # overrideable hook for updating message
end
after_initialize() click to toggle source
# File lib/rocket_cms/controllers/contacts.rb, line 56
def after_initialize
  # overrideable hook for updating message
end
ajax_success() click to toggle source
# File lib/rocket_cms/controllers/contacts.rb, line 50
def ajax_success
  render json: {ok: true}
end
message_params() click to toggle source
# File lib/rocket_cms/controllers/contacts.rb, line 65
def message_params
  params.require(:contact_message).permit(RocketCMS.config.contacts_fields.keys + [:name, :email, :phone, :content, :captcha, :captcha_key])
end
model() click to toggle source
# File lib/rocket_cms/controllers/contacts.rb, line 62
def model
  ContactMessage
end
process_ajax() click to toggle source
# File lib/rocket_cms/controllers/contacts.rb, line 47
def process_ajax
  true
end
redirect_after_done() click to toggle source
# File lib/rocket_cms/controllers/contacts.rb, line 53
def redirect_after_done
  redirect_to :contacts_sent
end
render_contacts_error() click to toggle source
# File lib/rocket_cms/controllers/contacts.rb, line 39
def render_contacts_error
  if request.xhr? && process_ajax
    render json: {errors: @contact_message.errors}, status: 422
  else
    flash.now[:alert] = @contact_message.errors.full_messages.join("\n")
    render action: RocketCMS.configuration.recreate_contact_message_action, status: 422
  end
end