Ruby on rails 3 Rails 3.2.13仅发送主题的联系方式
因此,我遵循了这个有缺陷的教程: …关于制作联系表格。它工作得很好。唯一的问题是它只发送主题。我想问题可能出在通知邮件中: 通知\u mailer.rbRuby on rails 3 Rails 3.2.13仅发送主题的联系方式,ruby-on-rails-3,ruby-on-rails-3.2,contact-form,Ruby On Rails 3,Ruby On Rails 3.2,Contact Form,因此,我遵循了这个有缺陷的教程: …关于制作联系表格。它工作得很好。唯一的问题是它只发送主题。我想问题可能出在通知邮件中: 通知\u mailer.rb class NotificationsMailer < ActionMailer::Base default :from => "noreply@youdomain.dev" default :to => "you@youremail.dev" def new_message(message) @me
class NotificationsMailer < ActionMailer::Base
default :from => "noreply@youdomain.dev"
default :to => "you@youremail.dev"
def new_message(message)
@message = message
mail(:subject => "[YourWebsite.tld] #{message.subject}")
end
end
class NotificationsMailer < ActionMailer::Base
default :from => "example@gmail.com"
default :to => "example@gmail.com"
def new_message(message)
@message = message
mail(:subject => "[liquid.radio] #{message.subject}", :body => "
From: #{message.name}
Reply to: #{message.email}
Subject: #{message.subject}
Message: #{message.body}")
end
end
基本上它是有效的。。。但它只发送主题。我还得到了一个完整的邮件发送一次,所有的东西,但主题。。。但我不记得我是怎么做到的
我是不是应该把这台电脑砸成一百万块然后大发雷霆
叹息
再次更新
这是电子邮件在上述设置下所说的:
主题:[液体。无线电]不管主题是什么。身体:完全
空白
不管我两周前做了什么,他们都是这么说的
Subject: Message from liquid.radio
Body:
A contact enquiry was made by Richard Pryor at 2013-06-17 23:36.
Reply-To: richard@pryor.com
Subject: Scared for no reason Body: Oh
no... Oh God no! What is that?!
我所做的就是和通知控制器混在一起。虽然我不记得了。。。为了我的生命。。。我所做的。但是,正如你所看到的。。。它发送完整的信息,因为它应该。。。但这是一个完全不同的主题
这里确实需要帮助。首先,此项目将生产设置放置在
config/application.rb
中。将GMail ActionMailer设置移动到config/environments/production.rb
。将letter\u opener
gem添加到Gemfile的开发组中
# Gemfile
group :development do
gem 'letter_opener'
end
在开发环境中添加字母开头器设置
# config/environments/development.rb
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :letter_opener
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
添加active\u attr
gem
# Gemfile
gem 'active_attr'
确保运行bundle安装
用健壮的ActiveAttr实现替换消息模型
# app/models/message.rb
class Message
include ActiveAttr::Model
attribute :name
attribute :email
attribute :subject
attribute :body
validates_presence_of :name, :email, :subject, :body
validates :email, :format => { :with => %r{.+@.+\..+} }, :allow_blank => true
end
改善路线
# config/routes.rb
get 'contact' => 'contact#new', :as => 'contact'
post 'contact' => 'contact#create', :as => 'contact'
确保您的电子邮件模板是正确的
# app/views/notifications_mailer/new_message.text.erb
Name: <%= @message.name %>
Email: <%= @message.email %>
Subject: <%= @message.subject %>
Body: <%= @message.body %>
#app/views/notifications_mailer/new_message.text.erb
姓名:
电邮:
主题:
正文:
更新:2013年12月12日
我在GitHub上创建了一个Rails 3.2项目,以帮助任何人寻找在Rails中创建联系人表单的现代解决方案。圣诞快乐!
首先,此项目将生产设置放置在
config/application.rb
中。将GMail ActionMailer设置移动到config/environments/production.rb
。将letter\u opener
gem添加到Gemfile的开发组中
# Gemfile
group :development do
gem 'letter_opener'
end
在开发环境中添加字母开头器设置
# config/environments/development.rb
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :letter_opener
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
添加active\u attr
gem
# Gemfile
gem 'active_attr'
确保运行bundle安装
用健壮的ActiveAttr实现替换消息模型
# app/models/message.rb
class Message
include ActiveAttr::Model
attribute :name
attribute :email
attribute :subject
attribute :body
validates_presence_of :name, :email, :subject, :body
validates :email, :format => { :with => %r{.+@.+\..+} }, :allow_blank => true
end
改善路线
# config/routes.rb
get 'contact' => 'contact#new', :as => 'contact'
post 'contact' => 'contact#create', :as => 'contact'
确保您的电子邮件模板是正确的
# app/views/notifications_mailer/new_message.text.erb
Name: <%= @message.name %>
Email: <%= @message.email %>
Subject: <%= @message.subject %>
Body: <%= @message.body %>
#app/views/notifications_mailer/new_message.text.erb
姓名:
电邮:
主题:
正文:
更新:2013年12月12日
我在GitHub上创建了一个Rails 3.2项目,以帮助任何人寻找在Rails中创建联系人表单的现代解决方案。圣诞快乐!
最后,以下是我所做的。。。我意识到这不是一个真正的解决方案。但我还是没有一个不同的 通知\u mailer.rb
class NotificationsMailer < ActionMailer::Base
default :from => "noreply@youdomain.dev"
default :to => "you@youremail.dev"
def new_message(message)
@message = message
mail(:subject => "[YourWebsite.tld] #{message.subject}")
end
end
class NotificationsMailer < ActionMailer::Base
default :from => "example@gmail.com"
default :to => "example@gmail.com"
def new_message(message)
@message = message
mail(:subject => "[liquid.radio] #{message.subject}", :body => "
From: #{message.name}
Reply to: #{message.email}
Subject: #{message.subject}
Message: #{message.body}")
end
end
class NotificationsMailer”example@gmail.com"
默认值:to=>”example@gmail.com"
def新建_消息(消息)
@消息=消息
邮件(:subject=>“[liquid.radio]{message.subject}”,:body=>”
发件人:#{message.name}
回复:#{message.email}
主题:#{message.Subject}
消息:#{Message.body}”)
结束
结束
这根本不是邮递员的工作方式。。。但至少它发出了一个完整的信息
如果你在一个时间紧迫。。。就像我是。。。这会让你达到目的。一旦我不再以任何其他方式收到空白电子邮件,我会接受一个真实的答案(可能是scarver2的答案)。最后,我就是这么做的。。。我意识到这不是一个真正的解决方案。但我还是没有一个不同的 通知\u mailer.rb
class NotificationsMailer < ActionMailer::Base
default :from => "noreply@youdomain.dev"
default :to => "you@youremail.dev"
def new_message(message)
@message = message
mail(:subject => "[YourWebsite.tld] #{message.subject}")
end
end
class NotificationsMailer < ActionMailer::Base
default :from => "example@gmail.com"
default :to => "example@gmail.com"
def new_message(message)
@message = message
mail(:subject => "[liquid.radio] #{message.subject}", :body => "
From: #{message.name}
Reply to: #{message.email}
Subject: #{message.subject}
Message: #{message.body}")
end
end
class NotificationsMailer”example@gmail.com"
默认值:to=>”example@gmail.com"
def新建_消息(消息)
@消息=消息
邮件(:subject=>“[liquid.radio]{message.subject}”,:body=>”
发件人:#{message.name}
回复:#{message.email}
主题:#{message.Subject}
消息:#{Message.body}”)
结束
结束
这根本不是邮递员的工作方式。。。但至少它发出了一个完整的信息
如果你在一个时间紧迫。。。就像我是。。。这会让你达到目的。一旦我不再以任何其他方式收到空白电子邮件,我将接受真正的答复(可能是scarver2)。请附上这些文件:
app/views/notifications\u mailer/new\message.text.erb
,app/controllers/contact\u controller.rb
,app/models/message.rb
完成。我加了三个。任何帮助都将不胜感激。还有人在吗?这是非常。。。非常令人沮丧。请告诉我有人能帮忙吗?我即将删除整个内容,并找到另一种在rails中创建表单的方法。。。但我发现的一切都是2008年的…坚持住。我正在从头开始重建这个项目。教程有点过时了。完成后,我将向您发送GitHub项目,并希望有解决方案。:)请附上这些文件:app/views/notifications\u mailer/new\u message.text.erb
,app/controllers/contact\u controller.rb
,app/models/message.rb
完成。我加了三个。任何帮助都将不胜感激。还有人在吗?这是非常。。。非常令人沮丧。请告诉我有人能帮忙吗?我即将删除整个内容,并找到另一种在rails中创建表单的方法。。。但我发现的一切都是2008年的…坚持住。我正在从头开始重建这个项目。教程有点过时了。完成后,我将向您发送GitHub项目,并希望有解决方案。:)我绝对做到了这一切。。。一切似乎都很好。。。但它仍然做着完全相同的事情。发送一封空白电子邮件。另外,dropbox链接不允许我下载。它显示了文件,让我点击下载。。。然后说没有了。你确定没有什么吗