I added the following in my production.rb environment file.
config.action_mailer.default_url_options = {host: "domain.com"}
In my view:
<%= tag("img", src: image_url("logo.png")) %>
However, when I look at the path in my email, I see a image_path, not URL.
http:///assets/logo.png
What am I doing wrong?
This is how it works in my application. Try this
<%= image_tag(attachments['logo.png'].url, style: 'margin: 5px') %>
Try asset_path instead of image_url in production email views.
You need to specify config.action_mailer.asset_host = "domain.com" in production.rb. Then use image_tag in your mailer view.
Related
For <%= image_path('star-half-big.png') %>
I am seeing: http://localhost:3000/assets//assets/star-half-big.png
I have confirmed that the image is available at /assets/star-half-big.png
Any idea why rails is generating paths like this, and how to fix?
Make sure you put the image under app/assets/images/ directory.
And, then try it using image_url:
<%= image_url('star-half-big.png') %>
Also, make sure you don't have config.assets.prefix = "/assets/" in your config file.
It could be that in your development.rb you have an asset_host config set.
Comment it out if so.
# config.action_controller.asset_host = "localhost:3000/assets/"
I've realized my mistake. I had for path: '/assets/' set in $.fn.raty.defaults = {} inside of raty.js
I now have path: '../' in $.fn.raty.defaults = {} and in my views:
starHalf : '<%= image_path('star-half-big.png') %>',
starOff : '<%= image_path('star-off-big.png') %>',
starOn : '<%= image_path('star-on-big.png') %>'
I'm trying to get a link_to to generate the full url link of a survey in my sample survey app. The way I'm doing it is this in my mailer view:
<p>The survey is located <%= link_to("here", survey_url(#survey)) %>.</p>
The link that's generated is http://localhost:3000/surveys/2.
However, when the same code is run in production, the link that's generated is http://example.herokuapp.com/surveys/2 when it should be http://example.com/surveys/2.
The config files:
development.rb:
config.action_mailer.default_url_options = { :host => 'localhost:3000'}
production.rb:
config.action_mailer.default_url_options = { :host => 'http://example.com'}
Any idea why heroku is adding .herokuapp to the end of the host url/what I can do to generate the url as http://example.com/surveys/2?
I'm having problems when resetting a password using Devise.
When I click on 'Send me reset password instructions', I get:
ArgumentError at /users/password
Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
It says that the problem is in /views/devise/mailer/reset_password_instructions.html.erb on line 5.
On line 5 in that file there is:
<p><%= link_to 'Change my password', edit_password_url(#resource, :reset_password_token => #resource.reset_password_token) %></p>
I have no idea how to setup a mailer in Rails although I have tried to. Can anybody help me with this?
Finally, you need to set up default url options for the mailer in each
environment. Here is the configuration for "config/environments/development.rb":
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
You need to specify the host so it can be shown in the confimation email.
You can create a default filter like this:
# application_controller.rb
before_filter :mailer_set_url_options
...
def mailer_set_url_options
ActionMailer::Base.default_url_options[:host] = request.host_with_port
end
I'm using S3 to serve my public folder & trying to build a simple URL to one of these assets.
My production.rb has:
config.action_controller.asset_host = "https://my-bucket.s3.amazonaws.com"
And this works perfect in my .erb files:
<%= image_tag("rails.png") %>
# => <img src="https://my-bucket.s3.amazonaws.com/rails.png" />
But I need a url (not a tag) for a GENERIC file type, like:
<%= asset_host "foo.bar" %>
# => https://my-bucket.s3.amazonaws.com/foo.bar
What is the magic, two-word, underscore joined, rails phrase that gives me this url?
Use <%= asset_path "foo.bar" %>.
Assets are working fine for my web views, but for some reason my Mailer doesn't use the asset pipeline. I am trying to use an image_tag in my mailer view:
=link_to image_tag("logo.png")
However, that renders as
<img alt="logo" src="http://mydomain.com/assets/logo.png">
instead of
<img alt="logo" src="http://mydomain.com/assets/logo-xxxxxxxxx...png">
Am I missing something here?
My settings are:
config.action_mailer.default_url_options = { :host => config.domain }
config.action_mailer.asset_host = "http://" + config.domain
Thank you!
Try to put in your mail template the following instead of the link_to ( the link_to makes no sense because you link here your image to nothing, and I don't see the a href as output in your html) :
= asset_path("logo.png")
also put in your specific environment file :
config.action_mailer.default :content_type => "text/html"
Like this you are sure that you always use HTML as default content type. If u are using images in the mails it is better to put it as html.