Reporting ActiveSupport::Duration in concise human readable formats
by Syed Aslam · 2 min read
Convert ActiveSupport::Duration objects to concise human readable formats like '2h 30m 45s' with locale support.
6 posts in total
by Syed Aslam · 2 min read
Convert ActiveSupport::Duration objects to concise human readable formats like '2h 30m 45s' with locale support.
by Syed Aslam · 1 min read
Accessing the headers sent by clients in rails spits out both headers along with other environment variables. This adds a bit of inconvenience if you want to process only the external headers.
by Syed Aslam · 2 min read
Easy way to set a background from a selected number of images in Rails. You can set a background image purely through CSS thanks to the 'background-size' property in CSS3. Using the `html` element is better than `body` as it's always at least the height of the browser window. You set a fixed and centered background on it, then adjust it's size using `background-size` set to the cover keyword.
by Syed Aslam · 1 min read
It's very common to want to highlight the current link within a navigation list for the current action being performed. In Rails, if you are using Ajax, then this is easy, handle the onclick event to highlight the current link.
by Syed Aslam · 1 min read
The flash provides a way to pass temporary objects between actions. Anything you place in the flash will be exposed to the very next action and then cleared out. Learn a way to add close buttons to flash messages in Rails templates.
by Syed Aslam · 1 min read
A traditional Rails application uses a single application. We interact with it by writing models that inherit from `ActiveRecord::Base` which translate connection details (from config/database.yml) via the method `establish_connection`. Let's see how to connect to multiple databases from a Rails app.