Images in rails 3.1 - moving to production - ruby-on-rails-3.1

My articles have images. I put the images in app/assests/images and store their location in a field in the database.
Then I can display them in by using:
<%= image_tag(#article.image) %>
But when I move to the production server, none of my images show up! The server's looking for assets/blank-d5dd6e3683b4753dfde3c70cf61f99b6.png rather than blank.png and it isn't available.
How do I sort this?

This is a problem I ran into when Rails 3.1 was released.
Normal assets
If your assets are manually placed by you then all you have to do is run:
rake assets:precompile
This will precompile your assets into public/assets.
It's best to precompile on your production server so you don't have unessential files on your development server.
Uploaded assets
If you are uploading images using something like Paperclip, then don't use the asset folder.
You need put your images in the public folder. In your case probably public/assets/articles
Further Info
RailsGuides - Asset Pipeline

Related

No images on Nuxt static site after running npm run generate

I am working on a small nuxt website for a client, i havnt been using nuxt for very long but so far what i do is add target: "static" to the config when i'm ready to build for production, then send the dist folder to backend for deployment, but now i notice that after i run npm run generate images and others assets like js files do not get added to he page.. i have tried to create a new dummy project just to test, chose static mode when setting up the project, added 1 image to the project and display it in index page using
<img src="~/path-to-file" />
the image will appear normally in dev server, will also appear if project is hosted on netlify, but will not appear in git-pages or local apache server
i am confused on why this is happening, typically adding target static fixes issues like this but not this time, please help
There are two main ways to display images through nuxt. One via the assets folder, the other via the static folder.
Any images in the /assets folder will be bundled with webpack. These images can be referenced using:
<img src="~/assets/image.png"/>
If you do not want images to be bundled by webpack, then save them in the /static folder and reference using the following format:
<img src="/image.png"/>
Currently, you are using ~/ , which is shorthand to the base directory. Once you build your site for production this will no longer work, because the structure is transformed - which is why there is a discrepancy between your environments.

How to fetch newly added images from VM in google cloud platform?

When I add images it is stored inside google cloud platform VM correctly.
But I am not able to fetch newly added images in my website.
If I redeploy project with newly added images in assets folder it is showing correctly.
I have verified there is no mistake on frontend or backend side.
Is it not possible to get live image update with VM?
Edit:
I have used Vue.js.
I am storing images inside src/assets folder.
When I save images in my website it is saved at src/assets folder.
I think it can only access things in dist folder after build.
Can you suggest where should I save my file?
I'm making an educateg guess it's some cache issue.
Instead of putting your image files inside the VM you can try storing them in a bucket that's accessible to public. The downside is that it can serve only static files (no PHP or anything).
You have to configure your load balancer to forward all your.domain.com/images/ requests to the bucket but that's actually quite easy. Have a look at my answer asking for such configuration.

Laravel Vapor - Assets (logo) on maintenance mode page

According to the docs we are able to put a 503.html document inside the root of our Laravel project.
You may customize the maintenance mode splash screen for your application by placing a 503.html file in your application's root directory.
I would however love to be able to put one or more assets on this page (for example our Logo) to make this page better more personal. Laravel Vapor automatically uploads your static assets to cloudfront, which is not a problem if you're using the asset() helper. However, are there any solutions already being made? I can't find any.
Is there anyone who has created a solution to make this happen?
With Vapor every time you deploy all the assets get a new cloudfront url. This is mostly fine for js and css which we change often. Images, logos etc do not change much.
Better to make another bucket on aws and hard code the path the image file in your 503. Doesn't need to be deployed every time. Your users browsers can cache it for as long as you set it in the bucket.
I'd like Vapor to only change asset urls if the files have changed but so far that is not the case.

How do you access assets in a Pakyow app on heroku?

Problem: Pakyow App deployed to Heroku and all JS and CSS sourced/linked in template head 404.
I assume this is a problem stemming from Heroku, but rather not one that I am aware of. As far as I know, Heroku allows static assets in the public directory.
Anyway, looking for some helpful pointers from Pakyow users.
The app (currently) is at http://pakyow-go.herokuapp.com and the repo can be found at http://github.com/jphager2/pakyow-go.
This is an unfortunate default config option in the currently released version. To get around it, add this to the production configuration block in app.rb:
app.static = true
The reason it works this way out of the box is in most production cases you don't want the app serving static files. This would instead be the responsibility of the HTTP server. On Heroku though, you want the app server to serve static files unless you host them from a CDN.

Why are images not getting served on starting production server?

I have a Rails 3.1.0 application on a live server which when started in development mode serves all images and favicon.ico nicely.
But when the same app is started in production environment, the favicon image/other images in public folder are not served and their paths throws a 404 error (Interestingly, the static images of the 404 page are also not served). Any clue Rails Gods?
I am using NginX + Unicorn + Rails 3.1.0. Assets pipeline is used for everything except for 404/500 error pages and favicon.
I needed to show the files in my public folder in production mode too. I set "config.serve_static_assets" to true in "config/environments/production.rb", and it worked.
Have you tried moving all your images to app/assets/images instead? That is where the asset pipeline in Rails 3.1 serves images from. (For example, in a fresh 3.1.0 app, the rails.png file is now in app/assets/images instead of 'public/images').
FYI; if you're pulling up CSS background images, then you need to put in 'assets/imagename.jpg' instead of the old route of even just 'imagename.jpg'

Resources