Forum: Ruby on Rails How do I use a RESTful helper with path_prefix?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
8217faf2bfdfa7daf10135d41ddd421e?d=identicon&s=25 Jeff Cohen (jeff)
on 2007-02-05 22:55
(Received via mailing list)
Once upon a time I had this in my routes.rb:

  map.client_home ':client/', :controller => 'orders', :action =>

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

  map.client_home ':client/', :controller => 'orders', :action =>
  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 =>
  map.resources :orders, :path_prefix => ':client/'

and in fact it works when I test through a browser, but not in my test

  def test_client_orders
    get orders_url(:client => 'myclient')
    assert_response :success

results in this:

NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.rewrite
actionpack/lib/action_controller/base.rb:522:in `url_for'
    (eval):19:in `orders_url'
actionpack/lib/action_controller/test_process.rb:451:in `send'

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?

This topic is locked and can not be replied to.