views:

56

answers:

2

Background: i'm using InstantRails 2.0

I wanted to add a new column to an existing table using the following syntax:

ruby script/generate migration add_fieldname_to_tablename fieldname:string

So I tried

ruby script/generate migration add_invites_to_user invites:integer ruby script/generate migration add_invites_to_users invites:integer

And to test it further

ruby script/generate migration AddInvites ruby script/generate migration AddInvites invites:integer

All of the above give me

builder.rb:175 in 'build': Illegal route: the :controller must be specified! (ArgumentError)

+1  A: 

Got it,

I had specified a route without indicating the controller.

ie map.connect 'users/invite/:id'

I fixed it by adding :controller => 'users'

map.connect 'users/invite/:id', :controller => 'users'

I setup the first route while the server was running and it worked fine!

ro
+1  A: 

An explanation of why this happens helps:

When you run script/generate Rails will instantiate your application, which involves loading your routes amongst other things. This may seem excessive but it's "for the best", as the other things loaded in the Rails initialization process such as plugins, gems and initializers could affect how the migration operates.

So yes, if you have bad routing code it will break when you try to generate anything.

Ryan Bigg
Ah, that's a handy explanation. I'm sure this will help me in the future. Cheers Ryan.
ro