Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using polymorphic_path, getting error "undefined method 'merge'"

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.

like image 222
Kelp Avatar asked Dec 17 '22 21:12

Kelp


1 Answers

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

like image 183
Ryan Avatar answered Feb 23 '23 02:02

Ryan