我正在使用多态性(polymorphism)为我的文章(Article)、个人资料(Profile)和照片(Photo)模型创建评论。这是我的文章显示页面的视图(view)代码:
<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>
以下是“show”控制器的文章:
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
错误出现在这一行:
| <%= link_to "Permalink", polymorphic_path(@commentable, comment), :action => :show %>
但我确信这个错误存在于所有使用polymorphic_path的其他行中。如果我将polymorphic_path替换为article_comment_path,则可以正常工作。
非常感谢您的帮助。