看一看的主題發生器的源代碼:
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,但使用Mongoid的是ar。
此時應更換線require 'rails/all'
在application.rb
文件以下行:http://mongoid.org/en/mongoid/docs/installation.html:約Mongoid安裝在
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
更多信息。
好吧,你是對的,但即使刪除需要'rails/all'這個錯誤仍然發生!我用-O創建了我的rails應用程序! – jturolla