红宝石2.2.6
rails 3.1.18
artwork.rb
class Artwork < ActiveRecord::Base
belongs_to :category
belongs_to :artwork_style
belongs_to :artist
has_many :artwork_prices, dependent: :destroy
accepts_nested_attributes_for :artwork_prices, allow_destroy: true
attr_accessible :description, :name, :category_id, :artwork_style_id, :artist_id, :artwork_prices_attributes
validates :name, :category_id, :artwork_style_id, :artist_id, presence: true
end
artwork_price.rb
class ArtworkPrice < ActiveRecord::Base
belongs_to :artwork
attr_accessible :effectivity_date, :price
validates :effectivity_date, :price, presence: true
validates :effectivity_date, uniqueness: true
end
管理员/ artwork.rb
form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs :multipart => true do
f.input :name
f.input :description
f.input :category, input_html: { class: "chosen-input", style: "width:75% !important" }, collection: Category.all.map{|u|[u.name, u.id]}, include_blank: true
f.input :artwork_style, input_html: { class: "chosen-input", style: "width:75% !important" }, collection: ArtworkStyle.all.map{|u|[u.name, u.id]}
f.input :artist, input_html: { class: "chosen-input", style: "width:75% !important" }, collection: Artist.all.map{|u|[u.name, u.id]}
f.has_many :artwork_prices, heading: "Prices", allow_destroy: true,
new_record: "Add Price" do |prc|
prc.input :price, as: :number
prc.input :effectivity_date, as: :date_picker
end
end
end
所以我使用ActiveAdmin,当我使用2.1.9时,它一切正常。但是,Heroku现在使用2.2.6作为默认值,所以我需要更新我的Ruby版本。所以当我推送我的代码时,删除和更新has_many记录有错误。
请在下方查看。感谢
这是删除记录后的日志:
NoMethodError (undefined method `name' for nil:NilClass):
2017-05-22T11:00:50.272004+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/associations/has_many_association.rb:58:in `cached_counter_attribute_name'
2017-05-22T11:00:50.272006+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/associations/has_many_association.rb:81:in `inverse_updates_counter_cache?'
2017-05-22T11:00:50.272007+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/associations/has_many_association.rb:91:in `delete_records'
2017-05-22T11:00:50.272008+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/associations/collection_association.rb:466:in `remove_records'
2017-05-22T11:00:50.272008+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/associations/collection_association.rb:459:in `block in delete_or_destroy'
2017-05-22T11:00:50.272009+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/associations/collection_association.rb:149:in `block in transaction'
2017-05-22T11:00:50.272009+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
2017-05-22T11:00:50.272010+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/transactions.rb:208:in `transaction'
2017-05-22T11:00:50.272011+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/associations/collection_association.rb:148:in `transaction'
2017-05-22T11:00:50.272012+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/associations/collection_association.rb:459:in `delete_or_destroy'
2017-05-22T11:00:50.272012+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/associations/collection_association.rb:231:in `delete'
2017-05-22T11:00:50.272013+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/associations/collection_association.rb:157:in `delete_all'
2017-05-22T11:00:50.272014+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/associations/collection_proxy.rb:46:in `delete_all'
2017-05-22T11:00:50.272014+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/associations/builder/has_many.rb:42:in `block in define_destroy_dependency_method'
2017-05-22T11:00:50.272016+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:418:in `_run__1754346321139042496__destroy__2258824630191763583__callbacks'
2017-05-22T11:00:50.272017+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:405:in `__run_callback'
2017-05-22T11:00:50.272017+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:385:in `_run_destroy_callbacks'
2017-05-22T11:00:50.272018+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:81:in `run_callbacks'
2017-05-22T11:00:50.272019+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/callbacks.rb:254:in `destroy'
2017-05-22T11:00:50.272020+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/transactions.rb:254:in `block in destroy'
2017-05-22T11:00:50.272021+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
2017-05-22T11:00:50.272022+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
2017-05-22T11:00:50.272022+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/transactions.rb:208:in `transaction'
2017-05-22T11:00:50.272023+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
2017-05-22T11:00:50.272024+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/transactions.rb:254:in `destroy'
2017-05-22T11:00:50.272025+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/bundler/gems/active_admin-bf364c3d1469/lib/active_admin/resource_controller/data_access.rb:187:in `block in destroy_resource'
2017-05-22T11:00:50.272025+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/core_ext/object/try.rb:36:in `call'
2017-05-22T11:00:50.272026+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/core_ext/object/try.rb:36:in `try'
2017-05-22T11:00:50.272028+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/bundler/gems/active_admin-bf364c3d1469/lib/active_admin/callbacks.rb:79:in `block (2 levels) in define_active_admin_callbacks'
2017-05-22T11:00:50.272029+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/bundler/gems/active_admin-bf364c3d1469/lib/active_admin/resource_controller/data_access.rb:186:in `destroy_resource'
2017-05-22T11:00:50.272032+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/inherited_resources-1.7.2/lib/inherited_resources/actions.rb:58:in `destroy'
2017-05-22T11:00:50.272038+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
2017-05-22T11:00:50.272039+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/abstract_controller/base.rb:167:in `process_action'
2017-05-22T11:00:50.272040+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_controller/metal/rendering.rb:10:in `process_action'
2017-05-22T11:00:50.272040+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
2017-05-22T11:00:50.272041+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:447:in `_run__4053046364437575293__process_action__3677914961710630719__callbacks'
2017-05-22T11:00:50.272042+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:405:in `__run_callback'
2017-05-22T11:00:50.272042+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
2017-05-22T11:00:50.272043+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:81:in `run_callbacks'
2017-05-22T11:00:50.272044+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/abstract_controller/callbacks.rb:17:in `process_action'
2017-05-22T11:00:50.272044+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_controller/metal/rescue.rb:29:in `process_action'
2017-05-22T11:00:50.272045+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
2017-05-22T11:00:50.272045+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/notifications.rb:123:in `block in instrument'
2017-05-22T11:00:50.272046+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
2017-05-22T11:00:50.272047+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/notifications.rb:123:in `instrument'
2017-05-22T11:00:50.272047+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
2017-05-22T11:00:50.272048+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
2017-05-22T11:00:50.272049+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
2017-05-22T11:00:50.272049+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/abstract_controller/base.rb:121:in `process'
2017-05-22T11:00:50.272050+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/abstract_controller/rendering.rb:45:in `process'
2017-05-22T11:00:50.272050+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_controller/metal.rb:203:in `dispatch'
2017-05-22T11:00:50.272051+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
2017-05-22T11:00:50.272052+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_controller/metal.rb:246:in `block in action'
2017-05-22T11:00:50.272052+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_dispatch/routing/route_set.rb:73:in `call'
2017-05-22T11:00:50.272053+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
2017-05-22T11:00:50.272054+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_dispatch/routing/route_set.rb:36:in `call'
2017-05-22T11:00:50.272055+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/journey-1.0.4/lib/journey/router.rb:68:in `block in call'
2017-05-22T11:00:50.272056+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/journey-1.0.4/lib/journey/router.rb:56:in `each'
2017-05-22T11:00:50.272056+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/journey-1.0.4/lib/journey/router.rb:56:in `call'
2017-05-22T11:00:50.272057+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_dispatch/routing/route_set.rb:608:in `call'
2017-05-22T11:00:50.272058+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/warden-1.2.7/lib/warden/manager.rb:36:in `block in call'
2017-05-22T11:00:50.272058+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/warden-1.2.7/lib/warden/manager.rb:35:in `catch'
2017-05-22T11:00:50.272059+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/warden-1.2.7/lib/warden/manager.rb:35:in `call'
2017-05-22T11:00:50.272060+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
2017-05-22T11:00:50.272061+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/rack-1.4.7/lib/rack/etag.rb:23:in `call'
2017-05-22T11:00:50.272061+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/rack-1.4.7/lib/rack/conditionalget.rb:35:in `call'
2017-05-22T11:00:50.272062+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_dispatch/middleware/head.rb:14:in `call'
2017-05-22T11:00:50.272063+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
2017-05-22T11:00:50.272063+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_dispatch/middleware/flash.rb:242:in `call'
2017-05-22T11:00:50.272068+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/rack-1.4.7/lib/rack/session/abstract/id.rb:210:in `context'
2017-05-22T11:00:50.272069+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/rack-1.4.7/lib/rack/session/abstract/id.rb:205:in `call'
2017-05-22T11:00:50.272070+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_dispatch/middleware/cookies.rb:341:in `call'
2017-05-22T11:00:50.272071+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/query_cache.rb:64:in `call'
2017-05-22T11:00:50.272071+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activerecord-3.2.18/lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
2017-05-22T11:00:50.272072+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
2017-05-22T11:00:50.272072+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:405:in `_run__33687098234565086__call__2258824630191763583__callbacks'
2017-05-22T11:00:50.272073+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:405:in `__run_callback'
2017-05-22T11:00:50.272074+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
2017-05-22T11:00:50.272074+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:81:in `run_callbacks'
2017-05-22T11:00:50.272075+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
2017-05-22T11:00:50.272075+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
2017-05-22T11:00:50.272076+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
2017-05-22T11:00:50.272077+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
2017-05-22T11:00:50.272077+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/railties-3.2.18/lib/rails/rack/logger.rb:32:in `call_app'
2017-05-22T11:00:50.272078+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/railties-3.2.18/lib/rails/rack/logger.rb:16:in `block in call'
2017-05-22T11:00:50.272079+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/tagged_logging.rb:22:in `tagged'
2017-05-22T11:00:50.272079+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/railties-3.2.18/lib/rails/rack/logger.rb:16:in `call'
2017-05-22T11:00:50.272080+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_dispatch/middleware/request_id.rb:22:in `call'
2017-05-22T11:00:50.272080+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/rack-1.4.7/lib/rack/methodoverride.rb:21:in `call'
2017-05-22T11:00:50.272081+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/rack-1.4.7/lib/rack/runtime.rb:17:in `call'
2017-05-22T11:00:50.272082+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/activesupport-3.2.18/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
2017-05-22T11:00:50.272082+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/rack-1.4.7/lib/rack/lock.rb:15:in `call'
2017-05-22T11:00:50.272083+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/actionpack-3.2.18/lib/action_dispatch/middleware/static.rb:63:in `call'
2017-05-22T11:00:50.272084+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/rack-cache-1.7.0/lib/rack/cache/context.rb:140:in `forward'
2017-05-22T11:00:50.272085+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/rack-cache-1.7.0/lib/rack/cache/context.rb:147:in `pass'
2017-05-22T11:00:50.272085+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/rack-cache-1.7.0/lib/rack/cache/context.rb:159:in `invalidate'
2017-05-22T11:00:50.272086+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/rack-cache-1.7.0/lib/rack/cache/context.rb:74:in `call!'
2017-05-22T11:00:50.272086+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/rack-cache-1.7.0/lib/rack/cache/context.rb:51:in `call'
2017-05-22T11:00:50.272087+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/railties-3.2.18/lib/rails/engine.rb:484:in `call'
2017-05-22T11:00:50.272088+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/railties-3.2.18/lib/rails/application.rb:231:in `call'
2017-05-22T11:00:50.272088+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/rack-1.4.7/lib/rack/content_length.rb:14:in `call'
2017-05-22T11:00:50.272089+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/railties-3.2.18/lib/rails/rack/log_tailer.rb:17:in `call'
2017-05-22T11:00:50.272090+00:00 app[web.1]: vendor/bundle/ruby/2.2.0/gems/rack-1.4.7/lib/rack/handler/webrick.rb:59:in `service'
2017-05-22T11:00:50.272091+00:00 app[web.1]: vendor/ruby-2.2.6/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
2017-05-22T11:00:50.272091+00:00 app[web.1]: vendor/ruby-2.2.6/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
2017-05-22T11:00:50.272092+00:00 app[web.1]: vendor/ruby-2.2.6/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
schema.rb
类别
create_table "categories", :force => true do |t|
t.string "name"
t.text "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "cover_image_file_name"
t.string "cover_image_content_type"
t.integer "cover_image_file_size"
t.datetime "cover_image_updated_at"
end
艺术家
create_table "artists", :force => true do |t|
t.string "name"
t.text "bio"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
artwork_style
create_table "artwork_styles", :force => true do |t|
t.text "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
答案 0 :(得分:1)
我认为Rails 3.1.8不支持Ruby 2.2,至少需要Rails 3.2.22。
答案 1 :(得分:0)
我修复了这个升级Ruby 2.2.6 Rails 4.2.0。