2016-02-01 130 views
-3

我收到了一個錯誤,如下,$ bundle exec rake db:seed。 我正在使用rails 3.2.2和mysql。任何其他模型都沒有定義。NoMethodError:未定義的方法`權益='

NoMethodError: undefined method `equity=' for #<Company:0x007fd1cdb5b2a0> 
/home/vagrant/codes/sample/vendor/bundle/ruby/2.2.0/gems/activemodel-3.2.2/lib/active_model/attribute_methods.rb:407:in `method_missing' 
/home/vagrant/codes/sample/vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.2/lib/active_record/attribute_methods.rb:148:in `method_missing' 
/home/vagrant/codes/sample/db/seeds.rb:15:in `<top (required)>' 
/home/vagrant/codes/sample/vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `load' 
/home/vagrant/codes/sample/vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `block in load' 
/home/vagrant/codes/sample/vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency' 
/home/vagrant/codes/sample/vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `load' 
/home/vagrant/codes/sample/vendor/bundle/ruby/2.2.0/gems/railties-3.2.2/lib/rails/engine.rb:520:in `load_seed' 
/home/vagrant/codes/sample/vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.2/lib/active_record/railties/databases.rake:309:in `block (2 levels) in <top (required)>' 
Tasks: TOP => db:seed 
(See full trace by running task with --trace) 

我的DB/seed.rb是這樣的:

@company = Company.new 
@company.ticker = "1111" 
@company.name = "Cheese Company" 
@company.year = "2015" 
@company.fixed_asset = 30000 
@company.current_asset = 20000 
@company.equity = 35000 
@company.long_term_liabilities = 8000 
@company.short_term_liabilities = 7000 
@company.revenue = 30000 
@company.operating_income = 15000 
@company.ibit = 10000 
@company.net_income = 3500 
@company.operation_cashflow = 5800 
@company.financing_cashflow = 5500 
@company.investment_cashflow = 2000 
@company.save 

和模型的定義是:

$ cat app/models/company.rb 
class Company < ActiveRecord::Base 
end 

$ cat db/migrate/20160131155124_create_companies.rb 
class CreateCompanies < ActiveRecord::Migration 
    def change 
    create_table :companies do |t| 
     t.string :ticker 
     t.string :name 
     t.string :year 
     t.decimal :fixed_asset 
     t.decimal :current_asset 
     t.decimal :long_term_liabilities 
     t.decimal :short_term_liabilities 
     t.decimal :revenue 
     t.decimal :operating_income 
     t.decimal :ibit 
     t.decimal :net_income 
     t.decimal :operation_cashflow 
     t.decimal :financing_cashflow 
     t.decimal :investment_cashflow 
     t.timestamps 
    end 
    end 
end 

比 '公司' 的任何其他模式尚未確定。 歡迎任何幫助,非常感謝。

+2

你看到你的'create_companies'遷移'equity'? – Anthony

回答

0

在在遷移轉增股本列也

class CreateCompanies < ActiveRecord::Migration 
    def change 
    create_table :companies do |t| 
     t.string :ticker 
     t.string :name 
     t.string :year 
     t.decimal :fixed_asset 
     t.decimal :current_asset 
     t.decimal :long_term_liabilities 
     t.decimal :short_term_liabilities 
     t.decimal :revenue 
     t.decimal :operating_income 
     t.decimal :ibit 
     t.decimal :net_income 
     t.decimal :operation_cashflow 
     t.decimal :financing_cashflow 
     t.decimal :investment_cashflow 
     t.decimal :equity 
     t.timestamps 
    end 
    end 
end 
+0

謝謝,這解決了這個問題..! – saku

相關問題