mardi 9 juin 2015

Rails Ancestry. How can I display a single comment with all its descendants?

helpers/comments_helpers.rb

def nested_comments(comments)
    comments.map do |comment, sub_comments|
      render(comment) + content_tag(:div, nested_comments(sub_comments), :class => 'nested_comments')
    end.join.html_safe
  end

def nested_comment(one_comment)
    one_comment.instance_eval do |comment, sub_comments|
      render(comment) + content_tag(:div, nested_comments(sub_comments), :class => 'nested_comments')
    end.join.html_safe
  end

controllers/comments_controller.rb

 def show
     @comment = Comment.find(params[:id])
 end

views/comments/show.html.erb

...
<%= nested_comment(@comment) %>
...

I keep getting this error and I don't know why: undefined method `render' for #

If I remove the render part of the method, I get another error for content_tag

Can someone tell me how to fix these errors?

Aucun commentaire:

Enregistrer un commentaire