Routing strangeness

I’m converting an application and adding specs so I have created a new Rails 3 app and am writing specs and migrating code over from the old app to the new as needed to get things to pass…

But I’m having a strange problem with routes – any routes that I specify with ‘resource’ or ‘resources’ vanish. Rake routes has nothing for them and tests fail. For example:

resources :accounts, :only => [':get, :post]
resources :assets, only: [:index]

result in no output from rake routes. However, things like:

root to: 'welcome#index', via: 'get'
get 'welcome/feedback', :controller => 'welcome', :action => 'feedback'

work as expected. The rake routes output from these four directives is simply:

            root GET /                           welcome#index
welcome_feedback GET /welcome/feedback(.:format) welcome#feedback

I must be missing something really simple – I’ve used these before in other Rails3 apps.with no problems but I just can’t figure this one out.

Duh… two minutes after I posted this, I saw the problem. :get & :post aren’t part of the standard set of resourceful routes so nothing is generated. And no error message is displayed - just silence. I meant to put :new, :create and, of course, that works just fine.

This could still happen to someone by just making a little typo, so I blogged about it at Nuby Ruby / Rails Tales: Silence is NOT golden.... Hopefully it’ll help someone out some time.

1 Like