1

我试图让这个插件工作。我读过其他线程,但我似乎不明白。

我正在尝试使我的文章模型可评论。如果我到目前为止所做的一切:

正确完成所有安装。

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
4

1 回答 1

1

确保将acts_as_commentable您想要评论的模型添加到您的模型中。在这里没有看到任何型号代码。

编辑: 您是否也在您的文章路线中添加了嵌套资源?

resources :articles do
    resources :comments
end
于 2013-04-12T18:16:43.917 回答