# SWM seeking new function in ActionView

**URL:** <https://www.ruby-forum.com/t/swm-seeking-new-function-in-actionview/186381>\
**Category:** Rails\
**Created:** [April 6, 2010, 4:21am UTC](https://www.ruby-forum.com/t/swm-seeking-new-function-in-actionview/186381 "2010-04-06T04:21:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fearless\_fool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fearless\_fool](https://www.ruby-forum.com/u/fearless_fool)\
**Post date:** [April 6, 2010, 4:21am UTC](https://www.ruby-forum.com/t/swm-seeking-new-function-in-actionview/186381/1 "2010-04-06T04:21:07Z")

</div>

(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):

```auto
class User < ActiveRecord::Base
  has_many :service_addresses
  accepts_nested_attributes_for :service_addresses, :allow_destroy =>
:true
end

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

class MeteredService < ActiveRecord::Base
  belongs_to :service_address
end
```

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

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

… but in the views/service\_addresses/\_form.html.erb partial, this  
call:

```auto
<%= 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

---

<div class="post-metadata">

**Author:** ![fearless\_fool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fearless\_fool](https://www.ruby-forum.com/u/fearless_fool)\
**Post date:** [April 6, 2010, 4:42am UTC](https://www.ruby-forum.com/t/swm-seeking-new-function-in-actionview/186381/2 "2010-04-06T04:42:41Z")

</div>

Solved my own problem once I remembered that routes.rb is what triggers  
the definition of the new\_\_\_path methods. Adding the  
missing:

map.resources :service\_addresses, :has\_many =\> :metered\_services

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

- ff
