I on Rails-Anwendung Migration von 3.2.13 bis 4.0.0 arbeitete, bevor die Anwendung ausgeführt wird, ich brauche eine Seed-Datei auszuführen:Rake abgebrochen! NoMethodError: nicht definierte Methode bei der Migration auf Rails 4.0
seeds.rb
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Mayor.create(:name => 'Daley', :city => cities.first)
# Create subscription plans
SubscriptionPlan.find_or_create_by_name(name: "free", amount: 0.00, renewal_period: 1, trial_period: 30, description: 'Free Plan')
SubscriptionPlan.find_or_create_by_name(name: "year", amount: 149.00, renewal_period: 12, trial_period: 30, description: "Year Plan")
Dies ist die Tabelle:
create_table "subscription_plans", :force => true do |t|
t.string "name"
t.decimal "amount", :precision => 10, :scale => 2
t.integer "renewal_period", :default => 1
t.integer "trial_period", :default => 1
t.text "description"
end
Während rake db ausgeführt wird: Samen, das ist der Fehler, den ich einen Fehler in der aktuellen Version immer bin, wo es in früheren versi in Ordnung ist auf. Fehler:
rake aborted! NoMethodError: undefined method `trial_interval' for
#<SubscriptionPlan:0x0000000622b0b8> Did you mean? trial_period /home/abc/.rvm/gems/[email protected]/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:436:in
`method_missing'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:131:in
`method_missing'
/home/abc/.rvm/gems/[email protected]/gems/activemodel-4.0.0/lib/active_model/validator.rb:151:in `block in validate'
/home/abc/.rvm/gems/[email protected]/gems/activemodel-4.0.0/lib/active_model/validator.rb:150:in `each'
/home/abc/.rvm/gems/[email protected]/gems/activemodel-4.0.0/lib/active_model/validator.rb:150:in `validate'
/home/abc/.rvm/gems/[email protected]/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:283:in
`_callback_before_39'
/home/abc/.rvm/gems/[email protected]/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:407:in
`_run__3876620741187521333__validate__callbacks'
/home/abc/.rvm/gems/[email protected]/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:80:in
`run_callbacks'
/home/abc/.rvm/gems/[email protected]/gems/activemodel-4.0.0/lib/active_model/validations.rb:373:in `run_validations!'
/home/abc/.rvm/gems/[email protected]/gems/activemodel-4.0.0/lib/active_model/validations/callbacks.rb:106:in
`block in run_validations!'
/home/abc/.rvm/gems/[email protected]/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:373:in
`_run__3876620741187521333__validation__callbacks'
/home/abc/.rvm/gems/[email protected]/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:80:in
`run_callbacks'
/home/abc/.rvm/gems/[email protected]/gems/activemodel-4.0.0/lib/active_model/validations/callbacks.rb:106:in
`run_validations!'
/home/abc/.rvm/gems/[email protected]/gems/activemodel-4.0.0/lib/active_model/validations.rb:314:in `valid?'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/validations.rb:70:in
`valid?'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/validations.rb:77:in
`perform_validations'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/validations.rb:51:in
`save'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/attribute_methods/dirty.rb:32:in
`save'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/transactions.rb:270:in
`block (2 levels) in save'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/transactions.rb:326:in
`block in with_transaction_returning_status'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in
`block in transaction'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in
`within_new_transaction'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in
`transaction'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/transactions.rb:209:in
`transaction'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/transactions.rb:323:in
`with_transaction_returning_status'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/transactions.rb:270:in
`block in save'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/transactions.rb:281:in
`rollback_active_record_state!'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/transactions.rb:269:in
`save'
/home/abc/.rvm/gems/[email protected]/gems/protected_attributes-1.0.3/lib/active_record/mass_assignment_security/persistence.rb:46:in `create'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/relation.rb:121:in
`block in create'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/relation.rb:270:in
`scoping'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/relation.rb:121:in
`create'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-deprecated_finders-1.0.4/lib/active_record/deprecated_finders/dynamic_matchers.rb:141:in `dispatch'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:67:in
`find_or_create_by_name'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:20:in
`method_missing'
/home/abc/.rvm/gems/[email protected]/gems/attr_encrypted-1.2.1/lib/attr_encrypted/adapters/active_record.rb:50:in
`method_missing_with_attr_encrypted'
/home/abc/Desktop/Proj2/db/seeds.rb:10:in `<top (required)>'
/home/abc/.rvm/gems/[email protected]/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in
`load'
/home/abc/.rvm/gems/[email protected]/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in
`block in load'
/home/abc/.rvm/gems/[email protected]/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in
`load_dependency'
/home/abc/.rvm/gems/[email protected]/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in
`load'
/home/abc/.rvm/gems/[email protected]/gems/railties-4.0.0/lib/rails/engine.rb:540:in
`load_seed'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:153:in
`load_seed'
/home/abc/.rvm/gems/[email protected]/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:181:in
`block (2 levels) in <top (required)>'
/home/abc/.rvm/gems/[email protected]/gems/rake-11.2.2/exe/rake:27:in
`<top (required)>'
/home/abc/.rvm/gems/[email protected]/bin/ruby_executable_hooks:15:in
`eval'
/home/abc/.rvm/gems/[email protected]/bin/ruby_executable_hooks:15:in
`<main>' Tasks: TOP => db:seed (See full trace by running task with
--trace)
Ich weiß nicht, woher dieses trial_interval kam. Ich habe die gesamte Anwendung durchsucht. Bitte hilf mir.
find_or_create_by Können Sie Ihr Modell posten? – danielrsmith
Sieht aus, als hätte jemand ein ähnliches Problem: http://StackOverflow.com/Questions/13537722/getting-the-railskits-SAAS-App-Up-and-Running-Wa-Mysql2-Server –
klingt wie Sie eine Validierung auf haben Dieses Feld –