Created
July 14, 2012 22:43
-
-
Save aalinat/3113728 to your computer and use it in GitHub Desktop.
rails upload attachment (contact form)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Contact</h1> | |
<%= form_tag("/send_to", :method=>'post', :multipart => true) do %> | |
<p> | |
Subject:<br /> | |
<%= text_field_tag "subject" %> | |
</p> | |
<p> | |
Priority: <br /> | |
<%= select_tag("priority", options_for_select([['Critical', '1'], | |
['Important', '2'],['Standard','3']], '3')) %> | |
</p> | |
<p> | |
Describe your problem:<br /> | |
<%= text_area_tag "description", "", :size=>"10x10" %> | |
</p> | |
<p> | |
Add an attachment:<br /> | |
<%= file_field_tag "attachment" %> | |
</p> | |
<p> | |
<%= submit_tag 'Submit', :class => 'btn btn-primary' %> | |
</p> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
New Message! | |
<%=@description%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StaticsController < ApplicationController | |
def contact | |
end | |
def send_to | |
subject = params[:subject] | |
description = params[:description] | |
attachment = params[:attachment] | |
Testmailer.do_contact(subject,description,attachment).deliver | |
flash[:notice] = "email sent" | |
redirect_to :back | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Testmailer < ActionMailer::Base | |
default :from => "[email protected]" | |
def do_contact(subject,description,attachment) | |
@description =description | |
if attachment | |
attachments[attachment.original_filename] = File.open(attachment.path, 'rb'){|f| f.read} | |
end | |
mail(:to => "[email protected]", :subject => subject) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment