Acts_as_commentable polimorphic assiciations

Hi,

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

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’

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?