How do I use a RESTful helper with path_prefix?

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:inorders_url’
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:inmethod_missing’

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs