Preparing rails project for production environment and a question about content_tag

Hi! Since I had hard time find details about production environment in guides or documentation, I decided to ask about it here.

So - what settings and actions should I do to make my project work when launched in production environment? Since I can’t run it to see how it works on localhost, I assume I need a remote server. What settings should I prepare or what should I think of to make sure it will work out? Will be glad to hear any advice on that matter.

Now I will move to the second question - can I use content_tag in my project? Documentation mentions that it uses legacy syntax that is supposed to be removed in the future. Does that mean this function is deprecated too? It has feature that allows to add HTML attributes by passing a hash, which equivalent tag method doesn’t offer (it does allow to do that in erb by accessing attributes property but I sadly can’t make use of it, since it doesn’t seem to work anyhow in plain ruby and that is important since I am writing a helper method) but I would like to be sure if I will be porting my project to the future version of rails, that I won’t need to rewrite it.

Production deployments vary quite a bit. Based on if you are using:

  • Hosting Environment (Heroku, Digital Ocean, other VM host like AWS or Google)
  • Containers / Not
  • App server (like puma, or passenger phusion)
  • Web servers (nginx, Apache)
  • Assets - Sprockets / Propshaft
  • CSS Preprocessing - SASS / SCSS
  • Javascript Preprocessing - Typescript / Webpacker / esbuild / etc.

So you need to find documentation about the production steps for each of those choices.

Usually it is a matter of setting your RAILS_ENV=production in that environment. Bundling your gems. And doing some form of pre-compilation/asset preparation (with sprockets that is bin/rails assets:precompile docs).

Usually a hosting provider will also have some relevant documentation:

You can technically run RAILS_ENV=production locally, but I would advise against it. As soon as you have real production data in your database then you risk something untested going wrong and messing up your production data.

Some people set up an additional environment (you can make custom ones!) so you can test the asset compilation, caching, and other production like configurations while using non-production data stores. You can learn more about that here:

content_tag is not officially deprecated yet (it would be throwing warnings if it were). But it might be in the future. Based on that language in the documentation, I’d encourage you to use the tag helper instead.


Thanks a lot for the answer, that will be quite helpful for me.