What's my problem ? named resources

Hi all,

I really have a bad problem. I can't make named resource paths to work.

If I use this: def test_can_show   get :show, :party_id => @bob.id, :id => @address.id   assert_select "\#address_contact_route_#{@address.id}_line1_edit[url=?]",       address_path(@bob, @address, :txt) end

I get a big bang error:   1) Error: test_can_show(AddressContactRoutesControllerTest::PartyWithAddressTest): NoMethodError: You have a nil object when you didn't expect it! The error occurred while evaluating nil.to_sym     /home/francois/src/xlsuite.org/config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/core_ext/hash/keys.rb:27:in `symbolize_keys'     /home/francois/src/xlsuite.org/config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/inflector.rb:250:in `inject'     /home/francois/src/xlsuite.org/config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/core_ext/hash/keys.rb:26:in `each'     /home/francois/src/xlsuite.org/config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/core_ext/hash/keys.rb:26:in `inject'     /home/francois/src/xlsuite.org/config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/core_ext/hash/keys.rb:26:in `symbolize_keys'     /home/francois/src/xlsuite.org/config/../vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:95:in `rewrite_path'     /home/francois/src/xlsuite.org/config/../vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:69:in `rewrite'     /home/francois/src/xlsuite.org/config/../vendor/rails/actionpack/lib/action_controller/base.rb:522:in `url_for'     (eval):19:in `address_path'     /home/francois/src/xlsuite.org/config/../vendor/rails/actionpack/lib/action_controller/test_process.rb:451:in `send'     /home/francois/src/xlsuite.org/config/../vendor/rails/actionpack/lib/action_controller/test_process.rb:451:in `method_missing'     ./test/functional/address_contact_routes_controller_test.rb:47:in `test_can_show'

My route is properly defined in routes: map.resources :parties, :path_prefix => "/admin" do |parties|   parties.resources :addresses, :controller => "address_contact_routes" end

So, what's my error ? Can anyone spot it ?

Thanks !

hey François (welcome back from vacation),

I've seen that with multiple params to the url helpers - I've solved it by identifying the required params with a symbol.

so address_path(:address_id => @address, @bob, :txt) # is :txt the respond_to format?

this is the general solution, but you may have to add symbols to other params.

cheers, Jodi

Hello Jodi,

I've seen that with multiple params to the url helpers - I've solved it by identifying the required params with a symbol.

so address_path(:address_id => @address, @bob, :txt) # is :txt the respond_to format?

this is the general solution, but you may have to add symbols to other params.

Thanks for your response. In fact, I found my solution for a slightly related problem. You can get the gory details on my blog:

http://blog.teksol.info/articles/2007/03/14/named-resources-with-name-prefixes

The solution was to use the correct named route:

  formatted_address_path(@address, @bob, :txt)

is the route to use.

Thanks for your time, Jodi.