Adding comments with gem/ Ruby on Rails

╄→尐↘猪︶ㄣ 提交于 2019-12-12 06:47:19

问题


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:


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



来源:https://stackoverflow.com/questions/20459291/adding-comments-with-gem-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!