I have an email form. But I'm making a test email form where a user can add a unique email, and have the email test send it to that particular email.
To make it easy, I decided to make the test email perform via ajax, and stick the whole thing inside of the other email form.
I can't figure out how to send the variables from my HAML to my controller
new.html.haml
- form_tag admin_email_blast_path do
Subject
%br
= text_field_tag 'subject', :class => "mass_email_subject"
%br
Body
%br
= text_area_tag 'message', '', :name => 'editor1', :class => "mass_email_body"
%br/
= submit_tag 'Send Email', :class => 'button'
.grid_3.right.align_right.suffix_1 # <= TEST EMAIL :D
= text_field_tag 'email', nil, :style => "width: 150px;", :class => "test_email_address"
= link_to 'Test Email', test_email_admin_email_blast_path, :class => 'button test_email'
JS
$(".test_email").live("click", function() {
var email = $(".test_email_address")
var subject = $(".mass_email_subject");
var body = $(".mass_email_body");
data = "email=" + email.val() + "&subject" + subject.val() + "&body" + body.val();
$.ajax({type: "GET",
url: $(this).attr("href"),
dataType: "script"
data: data
});
return false;
});
Controller
def test_email
debugger
email = params[:email]
subject = params[:subject]
body = params[:body]
Notifier.deliver_email_blast(email, subject, body)
end
routes.rb
admin.resource :email_blast, :member => {
:test_email => :get
}
I apologize ahead of time if this is a dumb newbie question. :(