Populating Tables with Data Using Migrations

I can think of very few Rails sites that don’t need some kind of data pre-populated in their tables. When you talk to a Rails developer, the first thing that comes to mind when talking about populating the db is fixtures. This is not what we’re talking about here. Fixtures populate your TEST database with [...]

Tags: , , , ,

Rotating Ruby on Rails Log Files Using Logrotate

If you don’t pay much attention to the size of your log files in your production apps, you might want to take a look! If left alone, files such as production.log can grow quite large and bog down your application or server’s performance. In Linux, there is a tool called logrotate to help you manage [...]

Tags: , ,

Pass Additional Parameters to REST Named Routes

Here’s a quick one, but a useful reference nonetheless. How do you pass additional parameters to REST named routes?
Say you have the following route from the restful_authentication plugin:

map.logout ‘/logout’, :controller => ’sessions’, :action => ‘destroy’

This enables you to say something like this:

redirect_to logout_url

And if you want to pass extra params to that URL? It’s as [...]

Tags: , , , ,

Using Reserved Words in your Database Tables

I was banging my head against the wall the other day for several hours wondering why an extremely simple MyModel.find(:all) call was giving me the error: ArgumentError: wrong number of arguments (0 for 1).
There was absolutely nothing strange about the table, my controller, or model object. The next day it dawned on me, I thought [...]

Tags: , , , ,

Going from acts_as_taggable_on_steroids to acts_as_taggable_on Plugin

For one reason or another, once I upgraded my app to Rails 2.1, I started getting these mysterious “stack level too deep” errors. I’m not too sure what that even means, but I won’t get into it here. After diving into the stack trace for a little while, I noticed that the problem was with [...]

Tags: , , , ,

Using Find Conditions on ActiveResource Objects

If you have a Rails app (app #1) which needs to communicate with another Rails app (app #2), chances are that app #2 is set up as a Web Service, and its controllers are RESTful, and that in app #1 you’re using ActiveResource. In case you’re not familiar with ActiveResource, please check out this excellent [...]

Tags: , , , ,

Use termios Gem With Capistrano to Keep Your Password Hidden

This is a quick tip, but a good one. If you use Capistrano to deploy your Rails app (which, umm, you really should) you will probably have noticed that your password is echoed on the screen when you deploy. This has always made me kinda nervous (I tend to have a mini panic attack every [...]

Tags: , , , , , ,

Custom Validation Messages In Rails, the Clean and Easy Way

Rails rocks, but let’s be honest. If there’s one thing that sucks about it out of the box, it’s validation and error message handling. This is probably one of the most often asked about topics, and I’ve read dozens of tutorials and seen many plugins intent on fixing the issue.
So, let’s take a second [...]

Tags: , , ,

Deploying to Multiple Environments with One Capistrano Recipe

For your average small-medium sized Rails app, you will likely be using Capistrano to deploy to your production server. Most Capistrano tutorials out there will painlessly (and by that I mean painfully) walk you through this. But as your app grows, you will likely need to deploy to more than one environment - test, [...]

Tags: , , , ,

Better Image Resize with attachment_fu and RMagick

One of the main problems I ran into when using attachment_fu to upload images is the resize functionality. Let’s say you’re letting users upload an avatar (and it’s not necessarily a square). Also, let’s not mess with thumbnails (a lot of other blog posts I’ve read on this subject specify a square thumbnail in addition [...]

Tags: , , , , ,