Hi,
When updating a ReferralProgram object that has nested Pages in it I
get the error in the subject line.
Rails generates parameters that look like this:
{"pages_attributes"=>{"0"=>{"body"=>"blabla",
"subject"=>"blabla",
"id"=>"1"}}}
When the id parameter is removed like this:
{"pages_attributes"=>{"0"=>{"body"=>"blabla"}}}
The exception is not raised. Any ideas on this?
The relevant part that 'crashes' the form:
form.html.haml
---
- form.inputs :name => I18n.translate("strings.pages") do
- form.semantic_fields_for :pages do |pages|
%h3= pages.object.title
%div.page_description= pages.label :description, pages.object.description
= pages.input :subject unless pages.object.name.eql?("thankyou_page")
= pages.input :body
Example console session:
ru...@user-laptop:~/rails/1referralprogram$ script/console
Loading development environment (Rails 2.3.8)
h = {"pages_attributes"=>{"0"=>{"body"=>"blabla",
"subject"=>"blabla",
"id"=>"1"}}}>> h = {"pages_attributes"=>{"0"=>{"body"=>"blabla",
?> "subject"=>"blabla",
?> "id"=>"1"}}}
=> {"pages_attributes"=>{"0"=>{"body"=>"blabla", "id"=>"1",
"subject"=>"blabla"}}}
>> r = ReferralProgram.new(h)
NoMethodError: undefined method `to_sym' for nil:NilClass
from
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/whiny_nil.rb:52:in
`method_missing'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2302:in
`expand_hash_conditions_for_aggregates'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2301:in
`each'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2301:in
`expand_hash_conditions_for_aggregates'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2333:in
`sanitize_sql_hash_for_conditions'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2266:in
`sanitize_sql'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1524:in
`merge_conditions'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1522:in
`each'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1522:in
`merge_conditions'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1834:in
`add_conditions!'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1717:in
`construct_finder_sql'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1578:in
`find_every'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:618:in
`find'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:638:in
`all'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/association_collection.rb:380:in
`send'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/association_collection.rb:380:in
`method_missing_without_paginate'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2178:in
`with_scope'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/association_proxy.rb:207:in
`send'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/association_proxy.rb:207:in
`with_scope'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/association_collection.rb:376:in
`method_missing_without_paginate'
from
/usr/lib/ruby/gems/1.8/gems/will_paginate-2.3.14/lib/will_paginate/finder.rb:170:in
`method_missing'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/nested_attributes.rb:349:in
`assign_nested_attributes_for_collection_association'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/nested_attributes.rb:244:in
`pages_attributes='
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2906:in
`send'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2906:in
`assign_attributes'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2902:in
`each'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2902:in
`assign_attributes'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2775:in
`attributes='
from
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2473:in
`initialize'
from
/home/user/rails/1referralprogram/app/models/referral_program.rb:34:in
`initialize'
from (irb):4:in `new'
from (irb):4>> h = {"pages_attributes"=>{"0"=>{"body"=>"blabla"}}}
=> {"pages_attributes"=>{"0"=>{"body"=>"blabla"}}}
>> r = ReferralProgram.new(h)
=> #<ReferralProgram id: nil, name: nil, title: nil, description: nil,
display_url: nil, destination_url: nil, image_file_name: nil,
image_content_type: nil, image_file_size: nil, image_updated_at: nil,
bonus_file_name: nil, bonus_content_type: nil, bonus_file_size: nil,
bonus_updated_at: nil, support_contact_name: nil,
support_email_address: nil, minimum_contacts_per_referral: 1,
minimum_clicks_per_referral: 0, deleted_at: nil, created_at: nil,
updated_at: nil>
>>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.