ruby-on-rails – 如何获取我的Rails应用程序的基本URL(例如http
发布时间:2020-12-16 22:15:20 所属栏目:百科 来源:网络整理
导读:我正在使用Paperclip来允许用户附加东西,然后我发送一封电子邮件,并希望将该文件附加到电子邮件中.我正在尝试读取文件并将其添加为附件,如下所示: # models/touchpoint_mailer.rbclass TouchpointMailer ActionMailer::Base def notification_email(touchpo
我正在使用Paperclip来允许用户附加东西,然后我发送一封电子邮件,并希望将该文件附加到电子邮件中.我正在尝试读取文件并将其添加为附件,如下所示:
# models/touchpoint_mailer.rb class TouchpointMailer < ActionMailer::Base def notification_email(touchpoint) recipients "me@myemail.com" from "Touchpoint Customer Portal <portal@touchpointclients.com>" content_type "multipart/alternative" subject "New Touchpoint Request" sent_on Time.now body :touchpoint => touchpoint # Add any attachments the user has included touchpoint.assets.each do |asset| attachment :content_type => asset.file_content_type,:body => File.read(asset.url) end end end 这给我以下错误没有这样的文件或目录 – /system/files/7/original/image.png?1254497688与堆栈跟踪说它是对File.read的调用.当我访问show.html.erb页面,并点击图像的链接,这是像http:// localhost:3000 / system / files / 7 / original / image.png?1254497688,图像显示精细. 如何解决这个问题? 解决方法
asset.url将URL返回给文件.这通常是/system/classname/xx/xx/style/filename.ext.你会把它放在一个image_tag中.
你想要asset.path.它返回文件的完整路径,通常是/home/username/railsapp/public/system/classname/xx/xx/style/filename.ext HTH. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读