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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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 =>
'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
This topic is locked and can not be replied to.