我正试图让这个插件工作。我已经阅读了其他帖子,但我似乎没有得到它。
我正在尝试使我的文章模型可评论。如果我到目前为止做了这件事:
正确完成所有安装。
class CommentsController < ApplicationController
def create
@article = Article.find(params[:id])
@user_who_commented = @current_user
@comment = Comment.build_from( @article, @user_who_commented.id, "Hey guys this is my comment!" )
end
end
文章#show:
<%= form_for @comment do |f| %>
<%= f.text_area :text %>
<%= f.submit "Post Comment" %>
<% end %>
路线:
devise_for :users
resources :dashboard
resources :users, :only => [:index,:show,:edit,:update]
resources :events
resources :januscript do
resources :quotes
end
resources :jmail, :only => [:index, :show]
resources :album
resources :video, :only => [:index, :show]
resources :photos
scope '/archive' do
resources :quotes, :only => [:index]
resources :articles, :only => [:index,:show]
end
resources :comments
我收到此错误消息:
undefined method `model_name' for NilClass:Class
答案 0 :(得分:1)
确保将acts_as_commentable
添加到您想要评论的模型中。这里没有看到任何型号代码。
修改强> 您是否也在文章的路线中添加了嵌套资源?
resources :articles do
resources :comments
end