Class: Alchemy::MessagesController
- Inherits:
-
BaseController
- Object
- ApplicationController
- BaseController
- Alchemy::MessagesController
- Defined in:
- app/controllers/alchemy/messages_controller.rb
Overview
Sending Messages:
To send Messages via contact forms you can create your form fields in the config.yml
Example:
Make an Element with this options inside your @elements.yml file:
- name: contactform
ingredients:
- role: mail_to
type: Text
- role: subject
type: Text
- role: mail_from
type: Text
- role: success_page
type: Page
The fields mail_to
, mail_from
, subject
and success_page
are recommended. The Alchemy::MessagesController
uses them to send your mails. So your customer has full controll of these values inside his contactform element.
Then make a page layout for your contact page in the page_layouts.yml
file:
- name: contact
unique: true
cache: false
elements: [pageheading, heading, contactform]
autogenerate: [contactform]
Disabling the page caching is strongly recommended!
Please have a look at the alchemy/config/config.yml
file for further Message settings.
Instance Method Summary collapse
-
#create ⇒ Object
:nodoc:.
-
#index ⇒ Object
:nodoc:.
-
#new ⇒ Object
:nodoc:.
Methods included from Modules
included, #module_definition_for, register_module
Methods included from AbilityHelper
Methods included from ConfigurationMethods
#configuration, #multi_language?, #multi_site?, #prefix_locale?
Instance Method Details
#create ⇒ Object
:nodoc:
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/alchemy/messages_controller.rb', line 56 def create # :nodoc: @message = Message.new() @message.ip = request.remote_ip @element = Element.find_by(id: @message.contact_form_id) if @element.nil? raise ActiveRecord::RecordNotFound, "Contact form id not found. Please pass the :contact_form_id in a hidden field. Example: <%= f.hidden_field :contact_form_id, value: element.id %>" end @page = @element.page if @message.valid? MessagesMailer.contact_form_mail(@message, mail_to, mail_from, subject).deliver redirect_to_success_page else Current.page = @page render template: "alchemy/pages/show" end end |
#index ⇒ Object
:nodoc:
44 45 46 47 48 49 |
# File 'app/controllers/alchemy/messages_controller.rb', line 44 def index # :nodoc: redirect_to show_page_path( urlname: @page.urlname, locale: prefix_locale? ? @page.language_code : nil ) end |
#new ⇒ Object
:nodoc:
51 52 53 54 |
# File 'app/controllers/alchemy/messages_controller.rb', line 51 def new # :nodoc: @message = Message.new render template: "alchemy/pages/show" end |