I've created an email feature in my application. It all works well except the text_area
does not seem to support new lines. As I add my text and hit the return key, the delivered email will contain only white spaces and no new lines. This is my index code:
<h1>Send email to all users</h1>
<br />
<%= form_tag :action => 'sendmail' %>
<p><label for="email_subject">Subject</label>
<%= text_field 'email', 'subject' %></p>
<br />
<label for="email_message">Message</label>
<br />
<%= text_area(:email, :message, :cols => 20, :rows => 40) %>
<br />
<br />
<%= submit_tag "Send" %>
<%= form_tag %>
Any help will be appreciated
Mark
This is my controller:
开发者_高级运维class MailMessageController < ApplicationController
def sendmail
email = params["email"]
recipient = email["user"]
subject = email["subject"]
message = email["message"]
MailMessage.deliver_contact(recipient, subject, message)
return if request.xhr?
render :file => 'mail_message/msg.dryml'
end
def index
render :file => 'mail_message/index.html'
end
end
This is my contact.erb file in my views:
<%= @message %>
<%= "\n" %>
-------
<%= "\n" %>
Please do not reply to this email.
Mark
Emails use views like all standard pages.
I think you just missed to use simple_format to render the \n.
See doc: http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-simple_format
When you cannot find a bug, the problem is usually that you are looking in the wrong place. I think that may be the issue here and that newlines are not showing up because of problems with your mail template, and is nothing to do with the form you showed us here ...
could you post the template you are using to display the mail?
<pre><%= @message %></pre>
may be what you are looking for ...
精彩评论