2010-09-10 55 views
3

我正在使用多态性为我的文章,配置文件和照片模型创建评论。下面是我的文章显示页面视图:使用polymorphic_path,得到错误“未定义的方法”合并“”

<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> 

这里是条“秀”控制器:

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的其他行中。如果我为article_comment_path交换polymorphic_path,它将起作用。

非常感谢您的帮助。

回答

11

从多态路径的定义来看,它需要一个参数,然后是一个可选的散列。我会假设,那么,你需要通过两个@commentable和评论作为一个参数数组

polymorphic_path([@commentable,comment])

+0

为什么我不能给予好评这个多! – 2014-11-18 02:33:58