开发者

I can't generate migrations - "illegal route the controller must be specified" - where am I going wrong?

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:st开发者_高级运维ring

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)


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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜