# polymorphic\_path not getting generated

**URL:** <https://discuss.rubyonrails.org/t/polymorphic-path-not-getting-generated/57632>\
**Category:** rubyonrails-talk\
**Created:** [March 2, 2011, 6:48am UTC](https://discuss.rubyonrails.org/t/polymorphic-path-not-getting-generated/57632 "2011-03-02T06:48:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![skt](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@skt](https://discuss.rubyonrails.org/u/skt)\
**Post date:** [March 2, 2011, 6:48am UTC](https://discuss.rubyonrails.org/t/polymorphic-path-not-getting-generated/57632/1 "2011-03-02T06:48:38Z")

</div>

Folks,

I am trying to use the Savage Beast plugin in a polymorphic way. I have setup my model as below

# Leaving out other details from models class Forum \< ActiveRecord::Base &nbsp;&nbsp;has\_one :recent\_topic, :class\_name =\> 'Topic', :order =\> 'sticky desc, replied\_at desc' &nbsp;&nbsp;belongs\_to :forum\_owner, :polymorphic =\> true # Helps keep track of which entity owns this forum end

class Topic \< ActiveRecord::Base &nbsp;&nbsp;belongs\_to :forum end

class School \< ActiveRecord::Base &nbsp;&nbsp;has\_many :forums, :as =\> :forum\_owner end

Now in the index.html.erb for forum I had the following line &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= link\_to t(:view), forum\_topic\_path(:forum\_id =\> forum, :id =\> forum.recent\_post.topic\_id, :page =\> forum.recent\_post.topic.last\_page, :anchor =\> forum.recent\_post.dom\_id) %\>

This line generates "[http://127.0.0.1:3001/forums/1/topics/1](http://127.0.0.1:3001/forums/1/topics/1)? page=1#posts-1" as the url. To make it polymorphic, I need the schools in the url so the url needs to change to "[http://127.0.0.1:3001/](http://127.0.0.1:3001/) schools/1/forums/1/topics/1?page=1#posts-1". So I replaced the above line with

\<%= link\_to t(:view), polymorphic\_path([@forum\_owner, forum, forum.recent\_topic], :page =\> forum.recent\_post.topic.last\_page, :anchor =\> forum.recent\_post.dom\_id) %\>

@forum\_owner and other variables are properly initialized. But this gives the error --\> undefined method `school\_forum\_topic\_path' for #\<ActionView::Base:0xaadcc08\>

Apparently the school\_forum\_topic\_path doesn't get generated. How do I make sure that school\_forum\_topic\_path function call gets generated to return the right path? In other words, how do you generate a multilevel polymorphic path?

Savage Beast plugin adds the following to the routes.rb

&nbsp;&nbsp;# Savage beast routes BEGIN &nbsp;&nbsp;map.resources :posts, :name\_prefix =\> 'all\_', :collection =\> { :search =\> :get } &nbsp;&nbsp;map.resources :forums, :topics, :posts, :monitorship

&nbsp;&nbsp;%w(forum).each do |attr| &nbsp;&nbsp;&nbsp;&nbsp;map.resources :posts, :name\_prefix =\> "#{attr}\_", :path\_prefix =\> "/#{attr.pluralize}/:#{attr}\_id" &nbsp;&nbsp;end

&nbsp;&nbsp;map.resources :forums do |forum| &nbsp;&nbsp;&nbsp;&nbsp;forum.resources :topics do |topic| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;topic.resources :posts &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;topic.resource :monitorship, :controller =\> :monitorships &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end

&nbsp;&nbsp;# Savage beast routes END &nbsp;&nbsp;map.resources :schools, :has\_many =\> :forums # \<------------ I added this line

Thanks for your help, -S
