SWM seeking new function in ActionView

(Okay, kidding about the SWM part, and I hope the spam filters agree…)

I have a three-level nested model, and can’t invoke the link_to path for
the “inner” nested pair without error. Here are the models (pardon the
code tags – they’re still useful):

class User < ActiveRecord::Base
  has_many :service_addresses
  accepts_nested_attributes_for :service_addresses, :allow_destroy =>

class ServiceAddress < ActiveRecord::Base
  belongs_to :user
  has_many :metered_services
  accepts_nested_attributes_for :metered_services, :allow_destroy =>

class MeteredService < ActiveRecord::Base
  belongs_to :service_address

In my views/users/_form.html.erb partial, this works fine:

<%= link_to 'new', new_user_service_address_path(@user) %>

… but in the views/service_addresses/_form.html.erb partial, this

<%= link_to 'new',
new_service_address_metered_service_path(@service_address) %>

results in undefined method `new_service_address_metered_service_path’
for ActionView. I thought that
new_service_address_metered_service_path() was defined as a result of
the accepts_nested_attributes_for AR.

Any ideas?

  • ff

Solved my own problem once I remembered that routes.rb is what triggers
the definition of the new___path methods. Adding the

map.resources :service_addresses, :has_many => :metered_services

in routes.rb fixed the problem. I’m learning…

  • ff

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs