small medium large xlarge

Dsc00115_pragsmall
12 Feb 2009, 20:02
Bruno Siqueira Silva (2 posts)

Hello, I’m following the book to create a nested route in my app. So, I defined in routes.rb: ` map.resources :companies, :has_many=>:contracts `

The thing is that a company is using single table inheritance (Company has two subclasses CompanyS and CompanyZ). and my test fail when trying to show contract/new.html.erb

<% form_for([@company,@contract]) do |f| %> <%= f.error_messages %> <p> <%= f.label :payment_type,I18n.t("activerecord.attributes.contract.payment_type") %><br /> <%= f.text_field :payment_type %> </p> <p>

I get the error

+Message: <”undefined method `company_s_contracts_path’ for #">

what’s the right to way to deal with this? thanks

Dsc00115_pragsmall
13 Feb 2009, 00:36
Bruno Siqueira Silva (2 posts)

I managed to fix part of the problem. Just need to replace the first argument for a symbol.

<% form_for([:company,@contract]) do |f| %> <%= f.error_messages %>

It works. Now the problem is with edit.html.erb. When I do the same in the form, it returns this error:

ActionView::TemplateError: company_contract_url failed to generate from {:action=>”show”, :controller=>”contracts”, :company_id=>#<Contract id: 1, company_id: 5, payment_type: “MyString”, initial_date: “2008-02-12”, end_date: “2009-02-12”, status: “MyString”, created_at: “2009-02-13 00:31:37”, updated_at: “2009-02-13 00:31:37”>}, expected: {:action=>”show”, :controller=>”contracts”}, diff: {:company_id=>#<Contract id: 1, company_id: 5, payment_type: “MyString”, initial_date: “2008-02-12”, end_date: “2009-02-12”, status: “MyString”, created_at: “2009-02-13 00:31:37”, updated_at: “2009-02-13 00:31:37”>} On line #3 of app/views/contracts/edit.html.erb `

<% form_for([:company,@contract]) do |f| %>
  <%= f.error_messages %> `

The contract is set to :company_id and I don’t know why. Anybody?

You must be logged in to comment