I've been asked to create a controller called 2010 on rails 2.3.2 but
script/generate controller 2010 fails with
wrong constant name 2010Helper
I tried creating everything manually, but still receive a 'wrong
constant name' error.
NameError in 2010Controller#index
wrong constant name 2010Controller
So, is there any way to fix this up to get it to work?
Here is a partial stack trace, btw.
Ruby won't let you make a class called 2010Controller, as it is not a
valid class name.
Why are you being told to create a controller of a specific name? Is
it for path reasons? If so, call it something else (./script/generate
controller twenty_ten) and then use a route to set things up from
/2010/ to what you just made.
Somebody wants the url to be http://example.com/2010/index.html. They
didn't say why, they just want it. I originally proposed a redirect
in the web server, but they think they want /2010 in the address bar.
I wondered if a route might be something to investigate, but I'm not
100% clear on how to reroute requests from /2010 to /twenty_ten. Will
a special route take care that link_to :controller =>
'twenty_ten', :action => 'foo' generates an html link like
map.connect '2010/:action', :controller => 'twenty_ten'
If using resources, I think this will work:
map.resource '2010', :controller => 'twenty_ten'
None of those are tested, but should be close I hope.
try a controller named twenty_ten, and:
map.resources :twenty_ten, :as => “2010”
Now that I read your words a bit more closely, I think you are
confused about what a route is and what a controller is.
By convention, this configuration:
means "things like /foo/action will go to controller foo" but that is
not required. It is merely convention. Like many things in Rails,
you can change things, but it requires configuration to do it. In
map.resource '2010', :controller => 'foo'
should be close. It says "I don't care what you think you want when
you see /2010, but I want it handled by the controller 'foo' instead."
Note that this does not mean that /foo exists, although if you leave
your default routes in it will. However, the more specific should
take priority and you should be good to go.