I am using Carrierwave gem + Mercury Editor and I want allow users to create mail campaigns and send them. Everything works well, but I have problems with inline images.
In image_uploader.rb I have
def store_dir
"#{uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
I have newsletters.contents column, and it includes preformatted HTML from Mercury including images.
So in email .eml file I have path like <img src="uploads/...">
instead of <img src="http://uploads/...">
If I change path to #{Rails.root}/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}
uploading not working at all.
Is there any way to fix this?
I solved it by adding gsub in mercury_update controller action
def mercury_update
newsletter = Newsletter.find(params[:id])
newsletter.title = params[:content][:newsletter_title][:value]
newsletter.content = params[:content][:newsletter_content][:value]
newsletter.update_attributes(content: newsletter.content.sub!('<img src="/uploads/', '<img src="http://host.com/uploads/'))
newsletter.save!
render text: ""
end
But I feel it is ugly solution
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.