Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 3发动机与线路故障_Ruby On Rails_Ruby On Rails 3_Routes_Rails Engines - Fatal编程技术网

Ruby on rails Rails 3发动机与线路故障

Ruby on rails Rails 3发动机与线路故障,ruby-on-rails,ruby-on-rails-3,routes,rails-engines,Ruby On Rails,Ruby On Rails 3,Routes,Rails Engines,我有一个引擎,带有此路由文件: Rails.application.routes.draw do resources :comments, :controller => 'opinio/comments' end 当我运行rake routes任务时,我得到了正确的输出 comments GET /comments(.:format) {:action=>"index", :controller=>"opinio/comments"}

我有一个引擎,带有此路由文件:

Rails.application.routes.draw do
  resources :comments, :controller => 'opinio/comments'
end
当我运行
rake routes
任务时,我得到了正确的输出

     comments GET    /comments(.:format)           {:action=>"index", :controller=>"opinio/comments"}
              POST   /comments(.:format)           {:action=>"create", :controller=>"opinio/comments"}
  new_comment GET    /comments/new(.:format)       {:action=>"new", :controller=>"opinio/comments"}
 edit_comment GET    /comments/:id/edit(.:format)  {:action=>"edit", :controller=>"opinio/comments"}
      comment GET    /comments/:id(.:format)       {:action=>"show", :controller=>"opinio/comments"}
              PUT    /comments/:id(.:format)       {:action=>"update", :controller=>"opinio/comments"}
              DELETE /comments/:id(.:format)       {:action=>"destroy", :controller=>"opinio/comments"}
我的控制器非常简单:

class Opinio::CommentsController < ApplicationController
  include Opinio::Controllers::InternalHelpers

  def index
    resource.comments.page(params[:page])
  end

  def create
    @comment = resource.comments.build(params[:comment])
    @comment.user = current_user
    if @comment.save
      flash[:notice] = I18n.translate('opinio.comment.sent', :default => "Comment sent successfully.")
    else
      flash[:error]  = I18n.translate('opinio.comment.error', :default => "Error sending the comment.")
    end
  end
end

我真的不知道Rails在哪里神奇地在控制器上添加了这个
注释
名称空间,我也不知道如何解决这个问题。

哇,这值得一个答案,所以没有人像我这样愚蠢

基本上,我在引擎模块中添加了以下内容:

mattr_accessor :name
@@name = "Comment"
在内部,每个模块上已经有一个方法
name
,我意外地覆盖了它,并导致了所有的错误。AS试图加载缺少的常量,但在我的Opinio模型中调用
name
时,它得到的是
“Comment”
,而不是
Opinio

给我自己和其他人一个提醒。 不要使用明显的名称和属性而不首先检查它们是否已经存在

mattr_accessor :name
@@name = "Comment"