# What's my problem ? named resources

**URL:** <https://www.ruby-forum.com/t/whats-my-problem-named-resources/88811>\
**Category:** Rails\
**Created:** [March 14, 2007, 4:35pm UTC](https://www.ruby-forum.com/t/whats-my-problem-named-resources/88811 "2007-03-14T16:35:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fbeausoleil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ec9cab/32.png) [@fbeausoleil](https://www.ruby-forum.com/u/fbeausoleil)\
**Post date:** [March 14, 2007, 4:35pm UTC](https://www.ruby-forum.com/t/whats-my-problem-named-resources/88811/1 "2007-03-14T16:35:15Z")

</div>

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 !

François Beausoleil  
[http://blog.teksol.info/](http://blog.teksol.info/)  
[http://piston.rubyforge.org/](http://piston.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![fbeausoleil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ec9cab/32.png) [@fbeausoleil](https://www.ruby-forum.com/u/fbeausoleil)\
**Post date:** [March 14, 2007, 4:47pm UTC](https://www.ruby-forum.com/t/whats-my-problem-named-resources/88811/2 "2007-03-14T16:47:16Z")

</div>

On 14-Mar-07, at 11:32 AM, François Beausoleil wrote:

> ```
> address_path(@bob, @address, :txt)
> 
> ```
> 
> end

> 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 ?

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

---

<div class="post-metadata">

**Author:** ![fbeausoleil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ec9cab/32.png) [@fbeausoleil](https://www.ruby-forum.com/u/fbeausoleil)\
**Post date:** [March 14, 2007, 5:15pm UTC](https://www.ruby-forum.com/t/whats-my-problem-named-resources/88811/3 "2007-03-14T17:15:25Z")

</div>

Hello Jodi,

2007/3/14, Jodi S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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](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.

François Beausoleil  
[http://blog.teksol.info/](http://blog.teksol.info/)  
[http://piston.rubyforge.org/](http://piston.rubyforge.org/)
