Rspec_scaffold URL generation errors

I am using Rails 2.3.4 and when I use rspec_scaffold the code that is
generated does not work without modification. For example, the link_to
that is generated for a show

<%= link_to 'Show', invoice_payment %>

fails with “invoice_payment_url failed to generate from
{:format=>#<InvoicePayment id: 1, …”

but if I change the code to

<%= link_to 'Show', :id => invoice_payment %> it works fine. This seems inconsistent with the documentation.

What am I doing wrong here?

Steve Scruggs wrote:

I am using Rails 2.3.4 and when I use rspec_scaffold the code that is
generated does not work without modification. For example, the link_to
that is generated for a show

<%= link_to 'Show', invoice_payment %>

fails with “invoice_payment_url failed to generate from
{:format=>#<InvoicePayment id: 1, …”

Judging from this error. It appears to me that you have a problem with
your routing. It appears to be trying to take the invoice_payment object
as the :format for the URL, which would not be correct. Make sure that
you don’t have a route in your routes.rb file that is interfering with
the resource routing.

but if I change the code to

<%= link_to 'Show', :id => invoice_payment %> it works fine. This seems inconsistent with the documentation.

This work, but is bizarre syntax. You’re forcing the invoice_payment.id
into the :id parameter making it work, but the “proper” syntax when not
using the shortcut syntax would be:

<%= link_to 'Show', invoice_payment_path(invoice_payment) %>

Robert W. wrote:

Steve Scruggs wrote:

I am using Rails 2.3.4 and when I use rspec_scaffold the code that is
generated does not work without modification. For example, the link_to
that is generated for a show

<%= link_to 'Show', invoice_payment %>

fails with “invoice_payment_url failed to generate from
{:format=>#<InvoicePayment id: 1, …”

Judging from this error. It appears to me that you have a problem with
your routing. It appears to be trying to take the invoice_payment object
as the :format for the URL, which would not be correct. Make sure that
you don’t have a route in your routes.rb file that is interfering with
the resource routing.

but if I change the code to

<%= link_to 'Show', :id => invoice_payment %> it works fine. This seems inconsistent with the documentation.

This work, but is bizarre syntax. You’re forcing the invoice_payment.id
into the :id parameter making it work, but the “proper” syntax when not
using the shortcut syntax would be:

<%= link_to 'Show', invoice_payment_path(invoice_payment) %>

Thanks for the quick reply Robert. The syntax that you suggest gives
the same error. The routes.rb file has the following as the first item.
map.resources :invoice_payments

Any other ideas where the issue may be?

Steve Scruggs wrote:
[…]

Thanks for the quick reply Robert. The syntax that you suggest gives
the same error.

Of course. You must fix your routing, I think.

The routes.rb file has the following as the first item.
map.resources :invoice_payments

That should be OK. How’s your output from “rake routes”?

Any other ideas where the issue may be?

Have you restarted your server since putting that line in the routes
file? (If you’re using Rails in development mode, this is probably not
the issue, but it’s quick and easy to try.)

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Steve Scruggs wrote:

The problem was caused by the plugin resource_fu. I removed the plugin
and the url’s are now generated as expected.

Marnen Laibow-Koser wrote:

Steve Scruggs wrote:
[…]

Thanks for the quick reply Robert. The syntax that you suggest gives
the same error.

Of course. You must fix your routing, I think.

The routes.rb file has the following as the first item.
map.resources :invoice_payments

That should be OK. How’s your output from “rake routes”?

Any other ideas where the issue may be?

Have you restarted your server since putting that line in the routes
file? (If you’re using Rails in development mode, this is probably not
the issue, but it’s quick and easy to try.)

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]
I have restarted the server many times, below is the rake routes output
/tuneup
{:action=>“show”, :controller=>“tuneup”}
/tuneup/:action
{:controller=>“tuneup”}
invoice_payments GET /invoice_payments(.:format)
{:action=>“index”, :controller=>“invoice_payments”}
POST /invoice_payments(.:format)
{:action=>“create”, :controller=>“invoice_payments”}
new_invoice_payment GET /invoice_payments/new(.:format)
{:action=>“new”, :controller=>“invoice_payments”}
edit_invoice_payment GET /invoice_payments/:id/edit(.:format)
{:action=>“edit”, :controller=>“invoice_payments”}
invoice_payment GET /invoice_payments/:id(.:format)
{:action=>“show”, :controller=>“invoice_payments”}
PUT /invoice_payments/:id(.:format)
{:action=>“update”, :controller=>“invoice_payments”}
DELETE /invoice_payments/:id(.:format)
{:action=>“destroy”, :controller=>“invoice_payments”}
decline_offers GET /decline_offers(.:format)
{:action=>“index”, :controller=>“decline_offers”}
POST /decline_offers(.:format)
{:action=>“create”, :controller=>“decline_offers”}
new_decline_offer GET /decline_offers/new(.:format)
{:action=>“new”, :controller=>“decline_offers”}
edit_decline_offer GET /decline_offers/:id/edit(.:format)
{:action=>“edit”, :controller=>“decline_offers”}
decline_offer GET /decline_offers/:id(.:format)
{:action=>“show”, :controller=>“decline_offers”}
PUT /decline_offers/:id(.:format)
{:action=>“update”, :controller=>“decline_offers”}
DELETE /decline_offers/:id(.:format)
{:action=>“destroy”, :controller=>“decline_offers”}
accept_job_offers GET /accept_job_offers(.:format)
{:action=>“index”, :controller=>“accept_job_offers”}
POST /accept_job_offers(.:format)
{:action=>“create”, :controller=>“accept_job_offers”}
new_accept_job_offer GET /accept_job_offers/new(.:format)
{:action=>“new”, :controller=>“accept_job_offers”}
edit_accept_job_offer GET /accept_job_offers/:id/edit(.:format)
{:action=>“edit”, :controller=>“accept_job_offers”}
accept_job_offer GET /accept_job_offers/:id(.:format)
{:action=>“show”, :controller=>“accept_job_offers”}
PUT /accept_job_offers/:id(.:format)
{:action=>“update”, :controller=>“accept_job_offers”}
DELETE /accept_job_offers/:id(.:format)
{:action=>“destroy”, :controller=>“accept_job_offers”}
projects GET /projects(.:format)
{:action=>“index”, :controller=>“projects”}
POST /projects(.:format)
{:action=>“create”, :controller=>“projects”}
new_project GET /projects/new(.:format)
{:action=>“new”, :controller=>“projects”}
edit_project GET /projects/:id/edit(.:format)
{:action=>“edit”, :controller=>“projects”}
project GET /projects/:id(.:format)
{:action=>“show”, :controller=>“projects”}
PUT /projects/:id(.:format)
{:action=>“update”, :controller=>“projects”}
DELETE /projects/:id(.:format)
{:action=>“destroy”, :controller=>“projects”}
project_assignments GET /project_assignments(.:format)
{:action=>“index”, :controller=>“project_assignments”}
POST /project_assignments(.:format)
{:action=>“create”, :controller=>“project_assignments”}
new_project_assignment GET /project_assignments/new(.:format)
{:action=>“new”, :controller=>“project_assignments”}
edit_project_assignment GET /project_assignments/:id/edit(.:format)
{:action=>“edit”, :controller=>“project_assignments”}
project_assignment GET /project_assignments/:id(.:format)
{:action=>“show”, :controller=>“project_assignments”}
PUT /project_assignments/:id(.:format)
{:action=>“update”, :controller=>“project_assignments”}
DELETE /project_assignments/:id(.:format)
{:action=>“destroy”, :controller=>“project_assignments”}
new_session GET /session/new(.:format)
{:action=>“new”, :controller=>“sessions”}
edit_session GET /session/edit(.:format)
{:action=>“edit”, :controller=>“sessions”}
session GET /session(.:format)
{:action=>“show”, :controller=>“sessions”}
PUT /session(.:format)
{:action=>“update”, :controller=>“sessions”}
DELETE /session(.:format)
{:action=>“destroy”, :controller=>“sessions”}
POST /session(.:format)
{:action=>“create”, :controller=>“sessions”}
users GET /users(.:format)
{:action=>“index”, :controller=>“users”}
POST /users(.:format)
{:action=>“create”, :controller=>“users”}
new_user GET /users/new(.:format)
{:action=>“new”, :controller=>“users”}
edit_user GET /users/:id/edit(.:format)
{:action=>“edit”, :controller=>“users”}
edit_password_user GET /users/:id/edit_password(.:format)
{:action=>“edit_password”, :controller=>“users”}
user GET /users/:id(.:format)
{:action=>“show”, :controller=>“users”}
PUT /users/:id(.:format)
{:action=>“update”, :controller=>“users”}
DELETE /users/:id(.:format)
{:action=>“destroy”, :controller=>“users”}
user_assets GET /users/:user_id/assets(.:format)
{:action=>“index”, :controller=>“assets”}
POST /users/:user_id/assets(.:format)
{:action=>“create”, :controller=>“assets”}
new_user_asset GET /users/:user_id/assets/new(.:format)
{:action=>“new”, :controller=>“assets”}
edit_user_asset GET /users/:user_id/assets/:id/edit(.:format)
{:action=>“edit”, :controller=>“assets”}
user_asset GET /users/:user_id/assets/:id(.:format)
{:action=>“show”, :controller=>“assets”}
PUT /users/:user_id/assets/:id(.:format)
{:action=>“update”, :controller=>“assets”}
DELETE /users/:user_id/assets/:id(.:format)
{:action=>“destroy”, :controller=>“assets”}
list_companies GET /companies/list(.:format)
{:action=>“list”, :controller=>“companies”}
companies GET /companies(.:format)
{:action=>“index”, :controller=>“companies”}
POST /companies(.:format)
{:action=>“create”, :controller=>“companies”}
new_company GET /companies/new(.:format)
{:action=>“new”, :controller=>“companies”}
edit_company GET /companies/:id/edit(.:format)
{:action=>“edit”, :controller=>“companies”}
company GET /companies/:id(.:format)
{:action=>“show”, :controller=>“companies”}
PUT /companies/:id(.:format)
{:action=>“update”, :controller=>“companies”}
DELETE /companies/:id(.:format)
{:action=>“destroy”, :controller=>“companies”}
company_assets GET /companies/:company_id/assets(.:format)
{:action=>“index”, :controller=>“assets”}
POST /companies/:company_id/assets(.:format)
{:action=>“create”, :controller=>“assets”}
new_company_asset GET
/companies/:company_id/assets/new(.:format) {:action=>“new”,
:controller=>“assets”}
edit_company_asset GET
/companies/:company_id/assets/:id/edit(.:format) {:action=>“edit”,
:controller=>“assets”}
pictures_company_asset GET
/companies/:company_id/assets/:id/pictures(.:format)
{:action=>“pictures”, :controller=>“assets”}
company_asset GET
/companies/:company_id/assets/:id(.:format) {:action=>“show”,
:controller=>“assets”}
PUT
/companies/:company_id/assets/:id(.:format) {:action=>“update”,
:controller=>“assets”}
DELETE
/companies/:company_id/assets/:id(.:format)
{:action=>“destroy”, :controller=>“assets”}
/:controller/service.wsdl
{:action=>“wsdl”}
/
{:action=>“index”, :controller=>“home”}
/confirm_email/:hash
{:action=>“confirm_email”, :controller=>“join”}
/logoff
{:action=>“destroy”, :controller=>“sessions”}
/no_permissions
{:action=>“no_permissions”, :controller=>“users”}
/users/edit_employer_profile
{:action=>“edit_employer_profile”, :controller=>“users”}
/users/update
{:action=>“update”, :controller=>“users”}
/my_hires
{:action=>“my_hires”, :controller=>“accept_job_offers”}
/list_my_project_assignments
{:action=>“list_my_project_assignments”,
:controller=>“project_assignments”}
/list_projects_assigned_to_me
{:action=>“list_projects_assigned_to_me”,
:controller=>“project_assignments”}
/swap_picture
{:action=>“swap_picture”, :controller=>“user_assets”}
/swap_video
{:action=>“swap_video”, :controller=>“user_assets”}
/:controller
{:action=>“index”}
/:controller/:action
/:controller/:action/:id
/:controller/:action/:id(.:format)