views:

884

answers:

4

Hello

I am getting an error when trying to use the resource route helper functions

 <%= link_to_remote "Delete", {
  :method => :delete, 
  :url=> phone_numbers_url(phone_number_display.id), 
  :update => "section_phone"
  }%>

and in my routes i have

       map.resources :phone_numbers

I get the following error

 You have a nil object when you didn't expect it!
 The error occurred while evaluating nil.to_sym

When I use

:url=> phone_numbers_url(:id => phone_number_display.id)

I no longer get the error but I get the unrestful url of

 http://localhost:3000/phone_numbers?id=1

I do no understand this error as phone_number_display.id is not null

A: 

if you've just created this route, you might need to restart your mongrel.

also you might want to run rake routes to double check the named route.

mkoga
yup I did that, it does not seem to be the issue
rube_noob
+1  A: 

There should not be a need to enclose the trailing arguments in {}, since they'll be transformed into a Hash anyway. See the api for link_to_remote. I don't know if that's what is causing the problem, but it's the first thing I'd try.

    <%= link_to_remote "Delete",
            :method => :delete, 
            :url=> phone_numbers_url(phone_number_display.id), 
            :update => "section_phone"
            %>

After that, if it's still not working, I'd look at the phone_numbers_url(phone_number_display.id) part, to check that I'm getting what I expect.

Mike Woodhouse
This code gives me the same error
rube_noob
Combined with the solution it works.Thanks
rube_noob
+2  A: 

You want the singular version of the route:

phone_number_url(phone_number_display)
François Beausoleil
Great, this was it.
rube_noob
+1  A: 

It might also be preferable to use phone_numbers_path(phone_number_display.id) as this will give you the relative path "/phone_numbers?id=1" instead of the full http://localhost.../.. path.

waldo