# Acts\_as\_commentable polimorphic assiciations

**URL:** <https://www.ruby-forum.com/t/acts-as-commentable-polimorphic-assiciations/179458>\
**Category:** Rails\
**Created:** [November 25, 2009, 2:34pm UTC](https://www.ruby-forum.com/t/acts-as-commentable-polimorphic-assiciations/179458 "2009-11-25T14:34:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![benol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bb73d2/32.png) [@benol](https://www.ruby-forum.com/u/benol)\
**Post date:** [November 25, 2009, 2:34pm UTC](https://www.ruby-forum.com/t/acts-as-commentable-polimorphic-assiciations/179458/1 "2009-11-25T14:34:05Z")

</div>

Hi,

I have the same/similar problem as Andrew in comment no 53 in here

> **[\#154 Polymorphic Association - RailsCasts](http://railscasts.com/episodes/154-polymorphic-association#comment_50322)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

When I include a partial on a page with  
\<% form\_for [@commentable, Comment.new] do |f| %\>  
I get undefined method `comments\_path’ for  
#ActionView::Base:0xb6cbe420  
(full stack trace below)

Any help appreciated.

M.

---- STACK TRACE ----  
/my\_proj\_home/vendor/rails/actionpack/lib/action\_controller/polymorphic\_routes.rb:109:in  
` __send__' /my_proj_home/vendor/rails/actionpack/lib/action_controller/polymorphic_routes.rb:109:in `polymorphic\_url’  
/my\_proj\_home/vendor/rails/actionpack/lib/action\_controller/polymorphic\_routes.rb:116:in  
`polymorphic_path' /my_proj_home/vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:298:in `apply\_form\_for\_options!’  
/my\_proj\_home/vendor/rails/actionpack/lib/action\_view/helpers/form\_helper.rb:272:in  
`form_for' /my_proj_home/app/views/comments/_new_comment.pl.html.erb:2:in `\_run\_erb\_app47views47comments47\_new\_comment46pl46html46erb\_locals\_commentable\_new\_comment\_object’

---

<div class="post-metadata">

**Author:** ![benol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bb73d2/32.png) [@benol](https://www.ruby-forum.com/u/benol)\
**Post date:** [November 25, 2009, 8:46pm UTC](https://www.ruby-forum.com/t/acts-as-commentable-polimorphic-assiciations/179458/2 "2009-11-25T20:46:58Z")

</div>

Michal B. wrote:

> When I include a partial on a page with  
> \<% form\_for [@commentable, Comment.new] do |f| %\>  
> I get undefined method `comments\_path’ for  
> #ActionView::Base:0xb6cbe420  
> (full stack trace below)

— I do a routing: —

map.resources :foo\_models, :has\_many =\> :comments

— That constructs several routes, one of those are: —

/foo\_models/1 - action show on foo\_models\_controller is executed  
/foo\_models/1/comments - action index on comments\_controller is executed

— The view foo\_models/index.html.erb want to render a partial: —

\<%= render :partial =\> ‘/comments/new\_comment’ %\>

— That partial contains: —

\<% form\_for [@commentable, Comment.new] do |f| %\>

— Question? : —

When accessing /foo\_models/1 the @commentable in that partial is nil  
since the “new” method of comments\_controller was not executed. How to  
handle this situation keepking the code DRY?
