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 has_one :recent_topic, :class_name => 'Topic', :order => 'sticky desc, replied_at desc' belongs_to :forum_owner, :polymorphic => true # Helps keep track of which entity owns this forum end
class Topic < ActiveRecord::Base belongs_to :forum end
class School < ActiveRecord::Base has_many :forums, :as => :forum_owner end
Now in the index.html.erb for forum I had the following line <%= 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? 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/ 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
# Savage beast routes BEGIN map.resources :posts, :name_prefix => 'all_', :collection => { :search => :get } map.resources :forums, :topics, :posts, :monitorship
%w(forum).each do |attr| map.resources :posts, :name_prefix => "#{attr}_", :path_prefix => "/#{attr.pluralize}/:#{attr}_id" end
map.resources :forums do |forum| forum.resources :topics do |topic| topic.resources :posts topic.resource :monitorship, :controller => :monitorships end end
# Savage beast routes END map.resources :schools, :has_many => :forums # <------------ I added this line
Thanks for your help, -S