ruby-on-rails - 使用 polymorphic_path,得到错误 "undefined method ' merge'"

标签 ruby-on-rails

我正在使用多态为我的文章、个人资料和照片模型创建评论。这是我的文章显示页面的 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/

相关文章:

ruby-on-rails - Rails - Heroku - Postgres - 不以明文形式存储敏感内容

javascript - ruby rails 4 : How to include Javascript and CSS?

ruby-on-rails - Ruby on Rails 3 文档 : "Can I"\ "Is it advisable" use (at least) a nested resource?

ruby-on-rails - 将foreign_key 值传递给Rails Controller 的更好方法

ruby-on-rails - 载波图像维度

ruby-on-rails - "desc"如何排序group_by?

ruby-on-rails - 在 PPC 上安装 GitLab 在 libv8 (3.11.8.17) 上失败,架构错误?

ruby-on-rails - 渲染 :update on Rails 3. 1.0 给我缺少模板更新

ruby-on-rails - react_on_rails 安装 : yarn is required error

sql - 在 SQL DB 中查询列中的特定字符串