I've got a model called ImplicitTest
. It's called this as having a Ruby object called Test
just breaks a lot of things in Rails.
However, I still want to expose it as a RESTful resource as test
(e.g. /tests
, /test/1/edit
and so forth). Furthermore, it would be great to keep the controller as TestsController
, although that's less important.
I was doing this by having simple resources :tests
line in my routes.rb file, but this fails for the RESTful forms (e.g. <%= form_for @test ... >
- this picks up that the @test object is of type ImplciitTest, and tries to lookup implicit_test_path
which does not exist.
I tried adding form_for options, but came to the conclusion that to have the form work for both new
and edit
actions, there was no one single, unified way of asking form_for() to use a different prefix for the path name lookup.
So I've been trying to approach the problem from the routing side. Is there a line I can add to the routes file that will allow me to:
- Have a model called ImplicitTest
- Have the path as /test
- Use the <%= form_for @test ... %> tag still
- Keep the controller as TestsController (optional)
I know I am departing the Golden Path to do this, but Rails isn't letting me use Test as a model name, but this is the name users will expect to see in the URL for this resource, so I'm hoping there is are simple routing option(s) that enable this.