ruby-on-rails – 如何获取我的Rails应用程序的基本URL(例如http:// localhost:3000)?

我正在使用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.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...