Adding comments with gem/ Ruby on Rails

2019-08-22 02:30发布

I have been learning some RoR and I have just created my first web application, a photosharing site that is basically a Pinterest copy. Now I am trying to add more functionality and I would like if users would be able to comment pins.

I'm using the Commontator Gem: https://github.com/lml/commontator/blob/master/README.md

The only problem is that I don't know where to put <%= commontator_thread(commontable) %> in my show.html.erb file. I have tried many different places but for some reason it ends up throwing an exception. Here is my show html.erb:

<%= link_to 'Back', pins_path %>

<div class="row">
  <div class="col-md-offset-2 col-md-8">
    <div class="panel panel-default">
      <div class="panel-heading center">
        <%= image_tag @pin.image.url(:medium) %>
      </div>
      <div class="panel-body">
        <p><%= @pin.description %></p>
        <p><strong><%= @pin.user.name if @pin.user %></strong></p>




        <%= link_to edit_pin_path(@pin) do %>
        <span class="glyphicon glyphicon-edit"></span>
        Edit


      <% end %>



      </div>
    </div>
  </div>
</div>

I would very much appreciate if someone could tell me where I should put that link.

Thank you!

1条回答
Deceive 欺骗
2楼-- · 2019-08-22 03:28

I think your issue here isn't about where you insert it in your show.html.erb. It seems like the model you want to be able to comment on is your Pin model. If so, the documentation (under the section Usage) indicates that you first need to add acts_as_commontable in your Pin model.

Then in show.html.erb

<%= commontator_thread(@pin) %>

The commontable is a instance of the model that acts_as_commontable which I assume here is @pin

查看更多
登录 后发表回答