[英]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.