2012-11-12 41 views
2

我有mongoid支架aplication並做: 軌摹引導:安裝Undefinied方法 '列' mongoid和引導

但是當我把:

rails g bootstrap:themed Contratos 

我有這樣的錯誤:

/usr/local/rvm/gems/ruby-1.9.3-p327/gems/twitter-bootstrap-rails-2.1.6/lib/generators/bootstrap/themed/themed_generator.rb:59:in block in columns': undefined method 'columns' for Contrato:Class (NoMethodError) 

回答

1

看一看的主題發生器的源代碼:

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" 

更多信息。

+0

好吧,你是對的,但即使刪除需要'rails/all'這個錯誤仍然發生!我用-O創建了我的rails應用程序! – jturolla

0

所有你需要做的就是添加一個「列」類方法你Mongoid模型,從而使發電機仍然響應正確:

def self.columns 
    self.fields.collect{|c| c[1]} 
end 

這種方法是基於薩科Garnil的響應,併爲我工作。