I am using polymorphism to create comments for my Article, Profile, and Photo models. Here is the view for my Article show page:
<div id="comment <%= comment.id %>">
<%= comment.title %>
| <%= link_to "Permalink", polymorphic_path(@commentable, comment), :action => :show %>
| <%= link_to "Reply", polymorphic_path(comment, @comment_child), :action => :new %>
| <%= link_to "Edit Comment", polymorphic_path(@commentable, comment), :action => :edit %>
| <%= link_to 'Delete Comment', [@commentable, comment], :confirm => "Are you sure?", :method => :delete %><br />
<%= comment.content %><br />
<%= comment.user.name %><br /><br />
<%= render :partial => 'comments/comment', :collection => @comment.children %>
</div>
Here is the Article 'show' controller:
def show
@article = Article.find(params[:id])
@commentable = Article.find(params[:id])
@comments = @commentable.comments.paginate(:page => params[:page])
@comment = Comment.new
@title = @article.title
end
The error appears on this line:
| <%= link_to "Permalink", polymorphic_path(@commentable, comment), :action => :show %>
but I am sure that this error is present in all of the other lines which use the polymorphic_path. It works if I exchange polymorphic_path for article_comment_path.
Thank you very much for help.
From the definition of polymorphic path, it is expecting one parameter and then an optional hash. I would assume, then, that you need to pass both @commentable and comment as one parameter in an array
polymorphic_path([@commentable,comment])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With