It’s been a while since I reviewed the documentation for rails new console command. There are a few useful features that I didn’t know about:
Category: Ruby & Rails
Speeding up office work with Ruby and IRB
I was just paying taxes ?. One of the steps involved was copying and pasting a few long reference numbers from a PDF into my banking app. The thing is, when copied, the reference number would contain extra spaces, after each character, making it invalid where I needed to paste it.
Don’t forget about X-Forwarded-Host header
Recently I was working on a Rails application on Heroku living behind a reverse proxy. This application serves requests coming to a specific folder on the target domain. For it to correctly generate full URLs, you have to somehow tell this app the hostname you want it to use. In Rails, you can configure a hostname in the environment config file, but that’s a static value, which has to be maintained and changed per environment. Also it does not work well if you want to access the application from multiple domains.
Speeding up bundle install with in-memory file system
On some of the servers I work with, due to cheap hard drives in software RAID configuration, I’ve found that bundle install can be extremely slow (take half an hour to complete). This obviously became unacceptable during deploys.
I thought that it might have something to do with how bundler writes a lot of small files during the installation of the gems. So I decided to try putting the deploy bundle directory (where all the gems are being installed) onto the in-memory filesystem. On Ubuntu this is /dev/shm.
It works flawlessly. The install time improved from half an hour down to a few seconds. After the bundle install is complete however, we do not want to leave the installed gems in the memory, as during restart they would be purged. So we just copy the directory back to the disk. Strangely enough, copying the whole directory from /dev/shm does not trash the disk so much and it only takes up to a minute for a few hundred MB of gems.
It’s cool to be able to find and utilize such a useful and simple part of Linux to solve and work around a slow hardware problem, while for everything else the server does, it’s still perfectly usable and more than capable of performing it.
Here’s my Capistrano 3 lib I use in my deploys that integrates this speedup:
```ruby namespace :bundler_speedup do task :symlink_to_shm do on roles(:all) do bundle_shm_path = fetch(:bundle_shm_path)
Effort – Personal To-do and Project manager
I have open sourced a Rails app that I’ve been personally using for years. The code is available on Github under the MIT license. From the README:
EQAFE – Ecommerce
This is one of the first projects where I started using Rails in production. EQAFE developed—over the years—from a simple checkout page to sell a single book to an ecommerce platform featuring thousands of products, affiliate program, gifts and more.
DIP Lite: E-learning Platform
DIP Lite is a free e-learning platform. Its fully automated in-browser experience connects the users with a personally assigned “buddy”: an experienced person that overviews and assist the user throughout the course. The user walks the course on her own pace as well as engage in daily exercises, complete with email notifications and communication with the course buddy provided by the course platform.
Projects Overview in 2012
These are some of the projects I’ve launched during 2012. This year was interesting as I switched from mainly using PHP as a backend language to Ruby (on Rails). Switching to Ruby was a welcome refreshment, the syntax is so close to natural language. I really enjoy the way it allows one to express the idea in code. There is little I need to say about Rails.
Equal Money System Website
The goal for this project was to create a presentation which immediately engages the user and allows them to interact with the website and information in a meaningful fashion. Therefore, instead of a static presentation, we came up with easy to use and immediately available voting in relation to the goals of the project that is being presented.
DIP Pro – Online Course Delivery Platform
E-learning project similar to DIP Lite but for more serious and advanced students, providing much more features including credit card payments, commission payouts, file (course material) delivery, multiple different courses divided into years and months and API for integration with other projects.