Re: rspec_scaffold URL generation errors

Steve Scruggs
Tue, 22 Sep 2009 14:27:42 -0000

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