Ruby   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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.

大佬总结

以上是大佬教程为你收集整理的ruby-on-rails – 如何获取我的Rails应用程序的基本URL(例如http:// localhost:3000)?全部内容,希望文章能够帮你解决ruby-on-rails – 如何获取我的Rails应用程序的基本URL(例如http:// localhost:3000)?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。