I'm having some trouble sending variables from a form to a post method which sends emails. The method receives the variable names instead of their content.
Form
= form_tag url(:amenities, :email_booking, name: :name, email_addr: :email, message: :message), :method => 'post' do
= flash_tag(:notice)
= field_set_tag do
%p
= text_field_tag :name, :placeholder => "Please enter your name"
%p
= text_field_tag :email, :placeholder => "Please enter your email address",
%p
= text_area_tag :message, :placeholder => "Message"
= field_set_tag(:class => 'buttons') do
= submit_tag 'SEND MESSAGE'
Controller
TourApart::App.controllers :amenities do
post :email_booking, with: [:name, :email_addr, :message] do
name = params[:name]
email_addr = params[:email_addr]
message = params[:message]
email do
from "[email protected]"
cc "[email protected]"
to email_addr
subject "We hope to see you soon"
locals :name => name, :message => message
body render('tour_booking_email')
content_type :plain
end
render "/"
end
end
this will (with the template, not shown) generate and send an email that looks like
DEBUG - Sending email to: email [email protected]
Date: Fri, 27 Jun 2014 09:48:12 +0100 From: [email protected]
To: email Cc: [email protected] Message-ID: <[email protected]> Subject: We hope to see you soon Mime-Version: 1.0 Content-Type: text/plain;
charset=UTF-8 Content-Transfer-Encoding: 7bitDear name, We will contact you very soon. Thank you for your interest in our services. We recieved the following message from you: "message" Please contact us at [email protected] if there is anything you would like to add or clarify." Sincerely,
puts params[:name]
in the controller will also return "name", so i'm guessing the post method is not receiving the data.
Any ideas?