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') %>'
Related
I am using the raty jquery library, and my images are broken only in production. This is what I've got in my view:
$(document).ready(function(){
$('#target-<%=w_index%>').raty({
half: true,
score: <%= #tastee.try(:jop_rank) || 0 %>,
starOn: <%= image_path('star-on.png') %>,
starOff: '<%= image_path('star-off.png') %>',
starHalf: '<%= image_path('star-half.png') %>',
cancelOn: '<%= image_path('cancel-on.png') %>',
cancelOff: '<%= image_path('cancel-off.png') %>'
});
and the rendered result is that the script has the correct url path and hash:
starOff: '/assets/star-off-6aaeebdaab93d594c005d366ce0d94fba02e7a07fd03557dbee8482f04a91c22.png'
but the rendered image tag has the assets prefix doubled:
<img alt="5" src="/assets//assets/star-off-6aaeebdaab93d594c005d366ce0d94fba02e7a07fd03557dbee8482f04a91c22.png" title="gorgeous">
What might be causing this?
I had previously installed and then removed the ratyrate gem.
I removed it from my gem file and from application.js.erb, however the js file was still in present my assets and compiling due to //= require_tree.
Removed the js file, precompiled and redeployed to solve.
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.
I have an angular file set up with my view template urls that gets used in my app when setting up routes. One of the urls will change based on the rails environment and I don't always know at least for the staging environment, what the url will be. So I was hoping to use rails request.host_with_port but when I run it I get the error
undefined local variable or method `request'
Here's the templates.js.erb file. Is there another way I can do this? Thanks.
angular.module('jobBoard')
.constant('templates', {
apply : '<%= asset_path('apply.html') %>',
detail : '<%= asset_path('detail.html') %>',
<% if Rails.env.development? || Rails.env.test? %>
apiUrl: 'http://localhost:3000/api'
<% elsif Rails.env.staging? %>
apiUrl: <%=request.host_with_port%>'/api'
<% else %>
apiUrl: 'http://www.knownurl.com/api'
<% 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.