Note that there are some explanatory texts on larger screens.

plurals
  1. POShowing HashWithIndifferentAccess from acts_as_commentable_with_thread in Rails 3.1
    primarykey
    data
    text
    <p>I am trying to display the contents of the nested comments and kind of stuck at something:</p> <p>I am using acts_as_commentable_with_threads plugin (it uses awesome_nested_set).</p> <p>In the controller, I have:</p> <pre><code>def show @team = Team.find(params[:id]) @all_comments = @team.comment_threads @root_comments = @team.root_comments @root_comment_content = @root_comments.first[:body] respond_to do |format| format.html end def add_new_comment @team = Team.find(params[:id]) @comment = Comment.build_from(@team, current_user.id, params[:comment]) @comment.parent_id = params[:parent_id] @comment.save! redirect_to :action =&gt; :show, :id =&gt; @team end </code></pre> <p>In the view, I have:</p> <pre><code>&lt;b&gt;Comments:&lt;/b&gt; &lt;% @root_comments.each do |comment| %&gt; &lt;%= comment.body %&gt; &lt;% end %&gt; </code></pre> <p>The result is: </p> <blockquote> <p>Comments: --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess body: asdvsdvasdfvasdvsdv --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess body: sdvdsv --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess title: TITITTLE body: BODYDDBB</p> </blockquote> <p>So the <code>@comment.body</code> is getting turned into a string.. How do I extract it the right way to get normal view? </p> <p>Thanks in advance )</p> <p>P.S. Would be absolutely amazing if somebody points me to an example of acts_as_commentable_with_threading - the description on git is not that clear and all the examples I found use acts_as_commentable</p> <p>EDIT: This is the form that I am using..</p> <pre><code> &lt;%= form_tag "add_new_comment" do %&gt; &lt;%= hidden_field_tag "id", @team.id %&gt; &lt;%= text_area_tag "comment[title]" %&gt;Title &lt;%= text_area_tag "comment[body]" %&gt;Body &lt;%= submit_tag "Post Comment" %&gt; &lt;% end %&gt; </code></pre> <p>EDIT : I updated the controller and now it kinda works, but there has to be a more elegants way.. is there?</p> <pre><code>@team = Team.find(params[:id]) @comment = Comment.build_from(@team, current_user.id, params[:comment]) @comment.body = params[:comment][:body] @comment.title = params[:comment][:title] @comment.parent_id = params[:parent_id] @comment.save! </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload