Ad

Rails Resource Restful Routes Helper Functions And Nil Oject Error

- 1 answer

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

Ad

Answer

You want the singular version of the route:

phone_number_url(phone_number_display)
Ad
source: stackoverflow.com
Ad