Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the base URL (e.g. http://localhost:3000) of my Rails app?

I'm using Paperclip to allow users to attach things, and then I'm sending an email and wanting to attach the file to the email. I'm trying to read the file in and add it as an attachment, like so:

# models/touchpoint_mailer.rb
class TouchpointMailer < ActionMailer::Base
  def notification_email(touchpoint)
    recipients "[email protected]"
    from "Touchpoint Customer Portal <[email protected]>"
    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

This gives me the following error No such file or directory - /system/files/7/original/image.png?1254497688 with the stack trace saying it's the call to File.read. When I visit the show.html.erb page, and click on the link to the image, which is something like http://localhost:3000/system/files/7/original/image.png?1254497688, the image is displayed fine.

How can I fix this problem?

like image 474
Wayne Molina Avatar asked Oct 02 '09 15:10

Wayne Molina


1 Answers

Typically root_url should provide this.

File.read is expecting a file path, not a url though. If you are generating the images, you should call the image generating code and return the bytes of the generated image instead of calling File.read(…)

like image 81
cwninja Avatar answered Nov 15 '22 18:11

cwninja