我正在使用多态为我的文章、个人资料和照片模型创建评论。这是我的文章显示页面的 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>
这是文章“显示” 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
错误出现在这一行:
| <%= link_to "Permalink", polymorphic_path(@commentable, comment), :action => :show %>
但我确信这个错误存在于所有使用 polymorphic_path 的其他行中。如果我将 polymorphic_path 交换为 article_comment_path,它会起作用。
非常感谢您的帮助。
最佳答案
从多态路径的定义来看,它需要一个参数,然后是一个可选的散列。那么,我假设您需要将 @commentable 和 comment 作为一个参数传递到数组中polymorphic_path([@commentable,comment])
关于ruby-on-rails - 使用 polymorphic_path,得到错误 "undefined method ' merge'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3681938/