查看主题生成器的源代码:
def columns
excluded_column_names = %w[id created_at updated_at]
if defined?(ActiveRecord)
rescue_block ActiveRecord::StatementInvalid do
@model_name.constantize.columns.reject{|c| excluded_column_names.include?(c.name) }.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type)}
end
else
rescue_block do
@model_name.constantize.fields.collect{|c| c[1]}.reject{|c| excluded_column_names.include?(c.name) }.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type.to_s)}
end
end
end
您面临的问题是您的应用程序定义了 ActiveRecord 但您的 ar 使用 Mongoid。
您应该将文件中的行替换require 'rails/all'
为application.rb
以下行:
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
有关 Mongoid 安装的更多信息,请参见:http: //mongoid.org/en/mongoid/docs/installation.html。