I have my rails app deployed with AWS Elastic beanstalk. However, when I open my app through Beanstalk environment, everything works fine except the images are not being shown. I tried many things to make it show but still not able to.
Can anyone help me?
I assume you are using Rails. If that's the case, you are missing the asset_path function.
Instead of:
<img src = "/assets/abc.jpg" />
You have to use something like:
<img src = "<%= asset_path('abc.jpg') %>" />
more info here: http://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html#method-i-asset_path
Related
I created a repo using sveltekit and successfully deployed it with Netlify, however the images will not load, their 'alt' attribute is all that shows up as seen in the image.
If I run the project locally using 'npm run dev' the images DO appear fine.
Here is the code where I have the img tags:
<ul>
<li><img src="/src/images/github.png" alt=GitHub></a></li>
<li><img src="/src/images/linkedin.png" alt=LinkedIn></a></li>
<li><img src="/src/images/email.png" alt=Email></a></li>
</ul>
Do I need to edit the paths somehow? Or maybe something in my svelte.config.js file:
import adapter from '#sveltejs/adapter-netlify';
/** #type {import('#sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter(),
}
};
export default config;
Put your image to this site https://cloudinary.com and get the link of the image and then try to use the link in src this will help you from the error.
Not very sure but SSR of sveltekit might be a problem in this case (Try vercel they seem to have better SSR support)! And yeah try putting your images in static folder .
In two Symfony 4 instances, I get different results with the same code.
In a twig template, I have the line
<img src="{{ asset('images/DM_logo.jpg')}}"/>
In the online server, all works well: i get the image and the generated URL is /images/DM_logo.jpg for the absolute URL http://mysite.mydomain.com/images/DM_logo.jpg
But, locally, with the access to http://localhost/mysite/, the generated url is /mysite/images/DM_logo.jpg for the absolute url http://localhost/mysite/images/DM_logo.jpg which generate a NotFoundHttpException.
If i change the template to
<img src="{{ asset('public/images/DM_logo.jpg')}}"/>
it works locally but not online...
I doesn't find how to use the same code online and locally. Advices?
configure this
# config/services.yaml
parameters:
router.request_context.host: 'example.org'
router.request_context.base_url: 'my/path'
asset.request_context.base_path: '%router.request_context.base_url%'
https://symfony.com/doc/current/routing.html#routing-generating-urls
I am facing issue in accessing public folder of laravel.
I am on ubuntu 17.10.
I am trying to run the app on localhost.
I am accessing like this:
<img src="{{URL::asset('public/assets/img/person.jpg')}}"/>
Also when checking the its source , its path is shown correct :
<img src="http://localhost:8000/public/assets/img/person.jpg"/>
It may seem duplicate but I've tried most of the solutions present on net.
You are calling the wrong directory
Instead of
<img src="{{URL::asset('public/assets/img/person.jpg')}}"/>
Use this instead
<img src="{{asset('assets/img/person.jpg')}}"/>
Considering the assets folder is existing in public folder.
I hope this will solve you :)
Just in case file had cached on your browser try to add query string on your file by doing this so browser will treat it as a new file
You shoud use Storage::get() to retrive the file url. See the docs
anyway, you don't need that public in the path:
Switch
<img src="{{URL::asset('public/assets/img/person.jpg')}}"/>
to
<img src="{{URL::asset('assets/img/person.jpg')}}"/>
I am almost done with upgrading my Rails3 app to Rails5; But I am facing a problem with assets pipelining and precompiling. We're using cdn as asset host.Now, What happens is that when I set config.assets.precompile to false in staging environment, the app doesn't load images from js.jsx files. At other places, the app is fetching the static assets (js,css,images) from the asset_host link that I've provided. But in some specific javascript files, The images is being pointed out to my app's domain like app.my_domain.com/assets/my_image.png,And it is giving 404 not found error.
In javascript, the code is something like
return (
<img src="/assets/my_image.png"></img>
)
Since this is a js file, I cannot use asset_path helper method here.
How to resolve this issue ?
PS: setting config.assets.precompile to true loads the image from app.my_domain.com/assets/my_image.png, but that's not what I want because of this. config.assets.compile=true in Rails production, why not?
Any help with this is highly appreciated. Thanks in advance.
I found an answer after some research. I changed the name of the file to js.jsx.erb and accordingly used asset_path helper method which rails provide.
return (
<img src = "asset_path 'my_image.png'"/>
)
It works.
In my rails (v2.3.8) app I have a static resource file which I've put at /public/myfile.kml No need for any special routes.rb setting right?
It serves up just fine at http://localhost:3000/myfile.kml
When I deploy (to passenger) it appears at http://myserver/myappname/myfile.kml
All is well so far...
I have a view (an erb file) which spews out javascript which needs to reference this file. The output needs to be '/myfile.kml' on localhost, and '/myappname/myfile.kml' in production, or maybe the full URLs as above, or maybe a relative url involving a bit of '../../../' (awkward with RESTful URLs).
Should I be able to do something like <%=url_for 'myfile.kml'%> ?
or '<%=ROOT_URL%>/myfile.kml'
I know there's an insanely easy answer to this question, but honestly I've had no luck finding it. Quite a few people talking about 'root_url' but what is that? A variable I can reference in a view? It's undefined.
I'm not sure about Rails 2.3.8, but in Rails 3 this value defaults to false.
edit config/environments/production.rb and set:
config.serve_static_assets = true
Also, here's a blog post that shows a helper for linking to a static resource (favicon)
http://ilconnettivo.wordpress.com/2008/07/28/favicon-on-rails/
'<%= ENV["RAILS_RELATIVE_URL_ROOT"] %>/myfile.kml'
<%= RAILS_ROOT + "/public/myfile.kml" %>
Inspection of rake routes reveals the helper root_path for use in views. For example <%= root_path + 'myfile.kml' %> By default will map to files under public/ in a rails application.
The latest (>2.3.6) is Rails.root, see:
http://joneslee85.wordpress.com/2010/05/27/the-dilemma-of-rails-root-vs-rails_root-complex/
Why not just replicate your production environment locally? A webserver is not very resource hungry and it can help resolve some ecosystem configuration issues like you're seeing here.