Morning (as appropriate) all!
I’m having a problem with rails 2.0.1 and am hoping somebody here
might be able to help me out.
I’m building a flex/rubyamf/rails app, and I’m having trouble saving
object graphs. Here’s an example.
Model: Contest
has_many Prizes
Model: Prize
belongs_to Contest
has_many Wins
Model: Win
belongs to Prize
When I create my Contest, I am populating Prizes, however, I’m not
populating Wins. When I get to ContestsController.create and do
@contest.save it’s blowing up (stack below) because it doesn’t like
that @contest.prizes.wins is nil. There are no validations on wins,
and I really suspect I SHOULD be able to do this.
Anybody have an idea what might be wrong? I know that my objects are
good when they hit the controller, so it’s not rubyamf at this
point. . .that was a whole other story ; ) Here are the params and
dump:
Parameters: {0=>#<Contest id: nil, name: “bbb”, start_date:
“2008-03-03 00:00:00”, end_date: “2008-03-09 00:00:00”,
submitted_by_id: nil, approved: false, approved_by_id: nil,
approved_at: nil, eligibility_id: 1, contest_category_id: 1,
frequency_id: 1, entry_instructions: nil, contest_url: nil, rules_url:
nil, company_url: nil, rules_text: nil, notes: nil, premium: false,
recommended: false, admin_notes: nil, created_at: nil, updated_at:
nil>, “contest”=>{“start_date”=>Mon Mar 03 00:00:00 -0600 2008,
“rules_url”=>nil, “name”=>“bbb”, “end_date”=>Sun Mar 09 00:00:00 -0600
2008, “contest_bookmarks”=>nil, “updated_at”=>nil, “premium”=>false,
“prizes”=>[#<Prize id: nil, quantity: 2, description: “bbb”,
estimated_value: 2, prize_category_id: 1, contest_id: nil,
admin_notes: nil, created_at: nil, updated_at: nil>],
“submitted_by_id”=>nil, “company_url”=>nil,
“contest_category”=>#<ContestCategory id: 1, name: “Instant”,
description: “Instant Win”, admin_notes: nil>, “approved_by”=>nil,
“comments”=>nil, “attributes_cache”=>{}, “ratings”=>nil, “notes”=>nil,
“approved”=>false, “attributes”=>{“start_date”=>Mon Mar 03 00:00:00
-0600 2008, “end_date”=>Sun Mar 09 00:00:00 -0600 2008,
“rules_url”=>nil, “name”=>“bbb”, “premium”=>false, “updated_at”=>nil,
“submitted_by_id”=>nil, “company_url”=>nil, “notes”=>nil,
“approved”=>false, “eligibility_id”=>1, “entry_instructions”=>nil,
“frequency_id”=>1, “contest_url”=>nil, “recommended”=>false,
“approved_by_id”=>nil, “approved_at”=>nil, “rules_text”=>nil,
“admin_notes”=>nil, “contest_category_id”=>1, “created_at”=>nil},
“eligibility_id”=>1, “eligibility”=>#<Eligibility id: 1, name:
“Alive”, description: “Aliv”, admin_notes: nil>,
“entry_instructions”=>nil, “frequency_id”=>1, “contest_url”=>nil,
“recommended”=>false, “approved_by_id”=>nil, “approved_at”=>nil,
“submitted_by”=>nil, “rules_text”=>nil, “created_at”=>nil,
“contest_category_id”=>1, “admin_notes”=>nil, “frequency”=>#<Frequency
id: 1, name: “Daily”, description: “Daily Entry”, interval: 0,
admin_notes: nil>}, “action”=>“create”, “controller”=>“contests”}
NoMethodError (undefined method each' for #<Class:0x2837654>): /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ base.rb:1459:in
method_missing’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
associations/association_collection.rb:164:in send' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ associations/association_collection.rb:164:in
method_missing’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
base.rb:1620:in with_scope' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ associations/association_collection.rb:164:in
send’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
associations/association_collection.rb:164:in method_missing' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ associations.rb:1067:in
validate_associated_records_for_wins’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
validations.rb:967:in send' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ validations.rb:967:in
run_validations’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
validations.rb:965:in each' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ validations.rb:965:in
run_validations’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
validations.rb:929:in valid_without_callbacks?' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ callbacks.rb:273:in
valid?’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
associations.rb:1072:in validate_associated_records_for_prizes' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ associations/association_proxy.rb:124:in
each’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
associations/association_proxy.rb:124:in send' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ associations/association_proxy.rb:124:in
method_missing’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
associations/association_collection.rb:162:in method_missing' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ associations.rb:1067:in
validate_associated_records_for_prizes’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
validations.rb:967:in send' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ validations.rb:967:in
run_validations’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
validations.rb:965:in each' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ validations.rb:965:in
run_validations’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
validations.rb:929:in valid_without_callbacks?' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ callbacks.rb:273:in
valid?’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
validations.rb:900:in save_without_transactions' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ transactions.rb:108:in
save’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
connection_adapters/abstract/database_statements.rb:66:in
transaction' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ transactions.rb:80:in
transaction’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
transactions.rb:100:in transaction' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ transactions.rb:108:in
save’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
transactions.rb:120:in rollback_active_record_state!' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ transactions.rb:108:in
save’
/app/controllers/contests_controller.rb:70:in create' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/ mime_responds.rb:106:in
call’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
mime_responds.rb:106:in respond_to' /app/controllers/contests_controller.rb:69:in
create’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
base.rb:1168:in send' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/ base.rb:1168:in
perform_action_without_filters’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
filters.rb:697:in call_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/ filters.rb:689:in
perform_action_without_benchmark’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
benchmarking.rb:68:in perform_action_without_rescue' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/1.8/benchmark.rb:293:in
measure’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
benchmarking.rb:68:in perform_action_without_rescue' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/ rescue.rb:199:in
perform_action_without_caching’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
caching.rb:678:in perform_action' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ connection_adapters/abstract/query_cache.rb:33:in
cache’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
query_cache.rb:8:in cache' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/ caching.rb:677:in
perform_action’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
base.rb:524:in send' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/ base.rb:524:in
process_without_filters’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
filters.rb:685:in process_without_session_management_support' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/ session_management.rb:123:in
process’
/vendor/plugins/rubyamf/app/actions.rb:139:in invoke' /vendor/plugins/rubyamf/app/actions.rb:86:in
run’
/vendor/plugins/rubyamf/app/filters.rb:53:in run' /vendor/plugins/rubyamf/app/filters.rb:51:in
each’
/vendor/plugins/rubyamf/app/filters.rb:51:in run' /vendor/plugins/rubyamf/app/filters.rb:49:in
upto’
/vendor/plugins/rubyamf/app/filters.rb:49:in run' /vendor/plugins/rubyamf/app/filters.rb:11:in
run’
/vendor/plugins/rubyamf/app/filters.rb:10:in each' /vendor/plugins/rubyamf/app/filters.rb:10:in
run’
/vendor/plugins/rubyamf/app/rails_gateway.rb:28:in service' /app/controllers/rubyamf_controller.rb:16:in
gateway’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
base.rb:1168:in send' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/ base.rb:1168:in
perform_action_without_filters’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
filters.rb:697:in call_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/ filters.rb:689:in
perform_action_without_benchmark’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
benchmarking.rb:68:in perform_action_without_rescue' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/1.8/benchmark.rb:293:in
measure’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
benchmarking.rb:68:in perform_action_without_rescue' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/ rescue.rb:199:in
perform_action_without_caching’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
caching.rb:678:in perform_action' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/ connection_adapters/abstract/query_cache.rb:33:in
cache’
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.1/lib/active_record/
query_cache.rb:8:in cache' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/ caching.rb:677:in
perform_action’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
base.rb:524:in send' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/ base.rb:524:in
process_without_filters’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
filters.rb:685:in process_without_session_management_support' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/ session_management.rb:123:in
process’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
base.rb:388:in process' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/ dispatcher.rb:171:in
handle_request’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
dispatcher.rb:115:in dispatch' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/ dispatcher.rb:126:in
dispatch_cgi’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.1/lib/action_controller/
dispatcher.rb:9:in dispatch' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in
process’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in
synchronize' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in
process’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in
process_client' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in
each’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in
process_client' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in
run’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in initialize' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in
new’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in
initialize’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in new' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in
run’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in
run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in
each’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in
run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in
run’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243 /Library/Ruby/Gems/1.8/gems/activesupport-2.0.1/lib/active_support/ dependencies.rb:489:in
load’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.1/lib/active_support/
dependencies.rb:489:in load' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.1/lib/active_support/ dependencies.rb:342:in
new_constants_in’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.1/lib/active_support/
dependencies.rb:489:in load' /Library/Ruby/Gems/1.8/gems/rails-2.0.1/lib/commands/servers/ mongrel.rb:64 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/1.8/rubygems/custom_require.rb:27:in require' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.1/lib/active_support/ dependencies.rb:496:in
require’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.1/lib/active_support/
dependencies.rb:342:in new_constants_in' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.1/lib/active_support/ dependencies.rb:496:in
require’
/Library/Ruby/Gems/1.8/gems/rails-2.0.1/lib/commands/server.rb:39
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/1.8/rubygems/custom_require.rb:27:in
require’
script/server:3
Thanks all!
H