简体   繁体   English

Rails在别针上注释gem Acts_as_commentable

[英]Rails comments gem Acts_as_commentable on pins

I have a rails app where users can upload pins, I want to use the [acts_as_commentable_gem][1] to allow users to comment pins, here is my config: 我有一个Rails应用程序,用户可以在其中上传图钉,我想使用[acts_as_commentable_gem][1]允许用户评论图钉,这是我的配置:

app/models/pin.rb app / models / pin.rb

class Pin < ActiveRecord::Base
    acts_as_commentable 
end

app/controlers/pins_controller.rb app / controlers / pins_controller.rb

def show
   @pin.find params[:id]
   @comment = @pin.comments.new
end

app/views/pins/show.html.erb app / views / pins / show.html.erb

<%= form_tag "/pins/add_new_comment" do %>
    <%= hidden_field_tag "id", post.id %>
    <%= text_area_tag "comment[comment]" %>
    <%= submit_tag "Pin Comment" %>
    <% end %>

app/models/comment.rb app / models / comment.rb

class Comment < ActiveRecord::Base

  include ActsAsCommentable::Comment

  belongs_to :commentable, :polymorphic => true

  default_scope -> { order('created_at ASC') }

  # NOTE: install the acts_as_votable plugin if you
  # want user to vote on the quality of comments.
  #acts_as_voteable

  # NOTE: Comments belong to a user
  belongs_to :user
end

app/controllers/pin_controller.rb app / controllers / pin_controller.rb

def add_new_comment
    pin = Pin.find(params[:id])
    pin.comments << Pin.new(params[:comment])
    redirect_to :action => :show, :id => pin
end

finally in my config/routes 终于在我的配置/路由

get "/pins/add_new_comment" => "pins#add_new_comment", :as => "add_new_comment_to_pins", :via => [:pin]

But I run to a routing error: 但是我遇到了路由错误:

undefined local variable or method `acts_as_commentable' for PinsController:Class PinsController:Class的未定义局部变量或方法“ acts_as_commentable”

I am really not sure where this error come from, any ideas? 我真的不确定这个错误来自哪里,有什么想法吗?

我不太确定,但您的路线不应该像

get "/pins/:id/add_new_comment" => "pins#add_new_comment", :as => "add_new_comment_to_pins"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Acts_as_commentable:AssociationTypeMismatch - Acts_as_commentable: AssociationTypeMismatch 在视图中使用act_as_commentable comment_threads方法在public_activity活动中嵌套注释 - using acts_as_commentable comment_threads method in view for nesting comments in public_activity activities 我可以创建而不更新的act_as_commentable吗? - acts_as_commentable can I create without updating? 格式中的第一个参数不能包含nil或为空(acts_as_commentable错误) - First argument in form cannot contain nil or be empty (acts_as_commentable error) 当我在Rails应用程序中使用build_from helper时,acts_as_commentable_with_threading gem无法正常工作。 - acts_as_commentable_with_threading gem is not working well when I use build_from helper in my Rails application. Acts_as_commentable_with_threading javascript切换不使用rails 5 - Acts_as_commentable_with_threading javascript toggle not working with rails 5 如何在Rails 4中安装gem act_as_reviewable - how to install gem acts_as_reviewable in rails 4 Rails act_as_votable宝石排序 - Rails acts_as_votable gem ordering 在轨上使用select2 gem和acts_as_taggable gem - using select2 gem with acts_as_taggable gem on rails acts_as_votable gem喜欢rails中页面上的所有帖子 - acts_as_votable gem likes all the posts on page in rails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM