I can't really test this right now but here's a thought:
- If you create a new ReferralProgram with new Pages there shouldn't
be a Page ID in the params because these Pages don't exist yet (If you
assign existing pages double check if a Page with that ID exists).
- If I remember this correctly multiple nested objects have to be in
an array in the params like:
"pages_attributes" => [ {"body"=>"blabla", "subject"=>"blabla"},
{"body" => "blublu", "subject"=>"blublu"} ]
Hope this helps a little!
Simon
On Sep 14, 5:08 pm, Commander Johnson <[email protected]>
wrote:
> 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_ni
> l.rb:52:in
> `method_missing'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:23
> 02:in
> `expand_hash_conditions_for_aggregates'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:23
> 01:in
> `each'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:23
> 01:in
> `expand_hash_conditions_for_aggregates'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:23
> 33:in
> `sanitize_sql_hash_for_conditions'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:22
> 66:in
> `sanitize_sql'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:15
> 24:in
> `merge_conditions'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:15
> 22:in
> `each'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:15
> 22:in
> `merge_conditions'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:18
> 34:in
> `add_conditions!'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:17
> 17:in
> `construct_finder_sql'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:15
> 78:in
> `find_every'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:61
> 8:in
> `find'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:63
> 8:in
> `all'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associatio
> ns/association_collection.rb:380:in
> `send'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associatio
> ns/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:21
> 78:in
> `with_scope'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associatio
> ns/association_proxy.rb:207:in
> `send'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associatio
> ns/association_proxy.rb:207:in
> `with_scope'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associatio
> ns/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.r
> b:170:in
> `method_missing'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/nested_att
> ributes.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_att
> ributes.rb:244:in
> `pages_attributes='
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:29
> 06:in
> `send'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:29
> 06:in
> `assign_attributes'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:29
> 02:in
> `each'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:29
> 02:in
> `assign_attributes'
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:27
> 75:in
> `attributes='
> from
> /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:24
> 73: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.