OS X Yosemite: Fixes for developers

Apple released OS X Yosemite to the public for free yesteday. So far, it isn’t bad. But, as a Web developer, I’ve hit a few bumps on the way, even during installation. Hopefully, if you’re a developer too, you’ll be wiser than me, do some research before installing, and maybe then this article will be of use to you.

This list isn’t meant to be exhaustive. I’m simply a Web developer often writing in Ruby nowadays, and I wish other Web developers will get back on track fast if they encounter the problems I have.… Continue reading “OS X Yosemite: Fixes for developers”

Ruby on Rails: Minify HTML, CSS, & JS, and compress with gzip

Update (2015-08-21): Do not use this. You will hate me for saying this, as this page is one of my most popular on the site, but after using my code on this page with Rails for quite a while, I came back on my own decision to use it. I knew compressing pages on every request would add some overhead, but I didn’t think it would be that significant – and it is, a lot.

While this would work with preprocessors like Middleman, which compresses all the files only once, doing so with an app generating pages on every request will slow down the application.

Continue reading “Ruby on Rails: Minify HTML, CSS, & JS, and compress with gzip”

Rack & Ruby on Rails: Force SSL

Nowadays, your Web app likely needs security and encryption with SSL. Once your SSL certificate and Web server are set up, one good way to ensure SSL is used is to redirect all HTTP traffic to HTTPS.

In the world of Ruby, I’ll explain how to do it for any application running with Rack or anything built with Ruby on Rails. Your Ruby on Rails application is probably running on top of Rack anyway, so the odds are you just need one of the two methods below.… Continue reading “Rack & Ruby on Rails: Force SSL”

Ruby on Rails: Manage local environment variables with dotenv

I mentioned how I prefer using environment variables to tailor the configuration of my Ruby on Rails app rather than going by the environment’s name. Here, I explain how I manage environment variables for a specify app using dotenv. (Figaro does a similar job – it’s mostly a matter of preference.)

Using dotenv means you can apply specific environment variables only to an app. You do not need to change the environment variables of your shell.

Like the README page linked above states, the simplest usage of dotenv is to add it wrapper tailored for Rails to your Gemfile for development and testing:

gem 'dotenv-rails', :groups => [:development, :test]

Update the bundle installation:

$ bundle

Set the environment variables you wish to use in your app in a .envContinue reading “Ruby on Rails: Manage local environment variables with dotenv”

Ruby on Rails: Use environment variables instead of environment names

Let’s put Ruby aside for a minute, close our eyes, and think of the times we write in JavaScript… Remember how we used to guess a browser’s capabilities based on its name and version? That quickly became a bad idea, which let us to check for the presence of the actual features instead of assuming they were there based on the reputation of the browser.

Now back in the world of Ruby on Rails. I notice we may rely a bit too much on the name of the environment, like staging or production, to enable to disable certain features.… Continue reading “Ruby on Rails: Use environment variables instead of environment names”