Once upon a time I had this in my routes.rb:
map.client_home ':client/', :controller => 'orders', :action => 'new'
All orders must be scoped within a client name, so this worked quite well. I used a before_filter to scoop up the @client object by doing a find_by_name.
Then I decided to expose the OrderController as a fully restful controller:
map.client_home ':client/', :controller => 'orders', :action => 'index' map.resources :orders
but I still needed orders to be prefixed with the /:client in the url; so this matched everything up:
map.client_home ':client/', :controller => 'orders', :action => 'index' map.resources :orders, :path_prefix => ':client/'
and in fact it works when I test through a browser, but not in my test code:
def test_client_orders get orders_url(:client => 'myclient') assert_response :success end
results in this:
NoMethodError: You have a nil object when you didn't expect it! The error occurred while evaluating nil.rewrite /Users/jeffreycohen/Sites/modem_app/trunk/config/../vendor/rails/ actionpack/lib/action_controller/base.rb:522:in `url_for' (eval):19:in `orders_url' /Users/jeffreycohen/Sites/modem_app/trunk/config/../vendor/rails/ actionpack/lib/action_controller/test_process.rb:451:in `send' /Users/jeffreycohen/Sites/modem_app/trunk/config/../vendor/rails/ actionpack/lib/action_controller/test_process.rb:451:in `method_missing' ./test/functional/orders_controller_test.rb:45:in `test_client_orders'
I've tried every permutation of the orders_url syntax I can think of.
How can I generate a url for a RESTful path when there's a variable in the path_prefix?
Thanks! Jeff