Ruby on rails 4 Rails注释gem在pin上充当可注释的角色
我有一个rails应用程序,用户可以在其中上载PIN,我想使用Ruby on rails 4 Rails注释gem在pin上充当可注释的角色,ruby-on-rails-4,pins,acts-as-commentable,Ruby On Rails 4,Pins,Acts As Commentable,我有一个rails应用程序,用户可以在其中上载PIN,我想使用[acts\u as\u commentable\u gem][1]允许用户对PIN进行注释,以下是我的配置: app/models/pin.rb class Pin < ActiveRecord::Base acts_as_commentable end def show @pin.find params[:id] @comment = @pin.comments.new end <%= for
[acts\u as\u commentable\u gem][1]
允许用户对PIN进行注释,以下是我的配置:
app/models/pin.rb
class Pin < ActiveRecord::Base
acts_as_commentable
end
def show
@pin.find params[:id]
@comment = @pin.comments.new
end
<%= form_tag "/pins/add_new_comment" do %>
<%= hidden_field_tag "id", post.id %>
<%= text_area_tag "comment[comment]" %>
<%= submit_tag "Pin Comment" %>
<% end %>
def add_new_comment
pin = Pin.find(params[:id])
pin.comments << Pin.new(params[:comment])
redirect_to :action => :show, :id => pin
end
app/views/pins/show.html.erb
class Pin < ActiveRecord::Base
acts_as_commentable
end
def show
@pin.find params[:id]
@comment = @pin.comments.new
end
<%= form_tag "/pins/add_new_comment" do %>
<%= hidden_field_tag "id", post.id %>
<%= text_area_tag "comment[comment]" %>
<%= submit_tag "Pin Comment" %>
<% end %>
def add_new_comment
pin = Pin.find(params[:id])
pin.comments << Pin.new(params[:comment])
redirect_to :action => :show, :id => pin
end
但我遇到了一个路由错误:
PinsController:Class的未定义局部变量或方法“作为可注释的”
get "/pins/add_new_comment" => "pins#add_new_comment", :as => "add_new_comment_to_pins", :via => [:pin]
我真的不确定这个错误是从哪里来的,有什么想法吗?我真的不确定,但您的路线不应该是这样的
get "/pins/:id/add_new_comment" => "pins#add_new_comment", :as => "add_new_comment_to_pins"