NoMethodError:未定义的方法`equity ='

时间:2016-02-01 12:14:56

标签: mysql ruby-on-rails ruby

我得到了一个类似于以下的错误,使用$ bundle exec rake db:seed。 我使用rails 3.2.2和mysql。没有定义任何其他模型。

$ cargo run --help
Run the main binary of the local package (src/main.rs)

Usage:
    cargo run [options] [--] [<args>...]

Options:
    -h, --help              Print this message
    --bin NAME              Name of the bin target to run
    --example NAME          Name of the example target to run
    -j N, --jobs N          The number of jobs to run in parallel
    --release               Build artifacts in release mode, with optimizations
    --features FEATURES     Space-separated list of features to also build
    --no-default-features   Do not build the `default` feature
    --target TRIPLE         Build for the target triple
    --manifest-path PATH    Path to the manifest to execute
    -v, --verbose           Use verbose output
    -q, --quiet             No output printed to stdout
    --color WHEN            Coloring: auto, always, never

If neither `--bin` nor `--example` are given, then if the project only has one
bin target it will be run. Otherwise `--bin` specifies the bin target to run,
and `--example` specifies the example target to run. At most one of `--bin` or
`--example` can be provided.

All of the trailing arguments are passed to the binary to run. If you're passing
arguments to both Cargo and the binary, the ones after `--` go to the binary,

我的db / seed.rb就像:

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)

和模型定义是:

@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

除了&#39;公司&#39;之外的任何其他型号尚未定义。 欢迎任何帮助,非常感谢。

1 个答案:

答案 0 :(得分: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