Sometimes during my work I find small things that confuse me, make me laugh or are the result of too much coding. From now on I'll post them under one "Rails Magic" banner.
I was looking for a way to prefix a path without prefixing a named routing helper. Somehow during the extensive two hours of hacking through the system I managed to end up with this brainfart:
scope '', :as => '', :path => 'abc' do
get '' => 'home#index'
What's so funny about it? Except the totally redundant '' part in
scope (I spent too much time in legacy code and forgot it's actually optional) there's a peculiar behaviour when we use empty string for
:as param and nest few of these
scope :as => '', :path => 'abc' do
scope :as => '', :path => 'def' do
scope :as => '', :path => 'ghi' do
get 'abc' => 'home#index'
This routing results in named routing looking like this:
___abc GET /abc/def/ghi/abc(.:format) home#index
For every empty
:as it prefixes named routing with
_. The solution? Simply skip the
:as => '' and the first parameter.
scope :path => 'abc' works just fine and I have completely no idea why I was trying to use the
:as param all that time :)