Using ActiveRecord Models in Rails' routes.rb

By: Johnathon Wright on: September 02, 2009

I broke the build today by using an ActiveRecord model in my routes file:

--- ruby dynamic_paths =

dynamic_paths.each do |path| map.connect path, :controller => 'feed', :action => 'show', :format => 'xml'


I wouldn't have expected this to be a problem, and it worked immediately, so I went on about my business. Unfortunately, Rails loads the entire Rails environment when it migrates. So, as the build server was migrating, Model.all failed (because the table wasn't there.)

Here is one solution, in the ever-popular and ever-readable "executable comments" style:

--- ruby def avoidingmigrationissues yield if Model.table_exists? end

avoidingmigrationissues do //original code end


Just checking that you are human. What would be the result of this code?

a = 3*(4/2); b = 1; a+b