0
votes

I am using rails 3.2 and ruby 1.9.2. When i try to create a record with some assigned hash value it throws ArgumentError (comparison of Fixnum with nil failed) exception. My source code is

doc = ArtifactImage.create!(vars)

The value and schema for Image are listed below.

vars : {:parent=>#<ArtifactContainer id: 23, artifact_container_type_id: 2, party_id: 11, parent_id: 21, folder_id: nil, filing_center_group_id: nil, artifact_source_type_id: nil, display_date: nil, record_date: nil, display_name: "Pictures", path: "/bathakarai/Pictures", file: nil, description: nil, type: "ArtifactContainer", recycled: false, discarded_date: nil, signed: false, phr: true, record_status_id: 1, created_at: "2013-07-19 04:29:39", updated_at: "2013-07-19 04:29:39", lock_version: 2, lft: nil, rgt: nil>, :file=>"clip-art-tom-and-jerry-381931.jpg", :display_name=>"Pictures", :artifact_source_type_id=>3, :party_id=>11, :folder_id=>nil}

ArtifactImage : ArtifactImage(id: integer, artifact_container_type_id: integer, party_id: integer, parent_id: integer, folder_id: integer, filing_center_group_id: integer, artifact_source_type_id: integer, display_date: datetime, record_date: date, display_name: string, path: string, file: string, description: string, type: string, recycled: boolean, discarded_date: datetime, signed: boolean, phr: boolean, record_status_id: integer, created_at: datetime, updated_at: datetime, lock_version: integer, lft: integer, rgt: integer)

The same code is working fine in rails-2. Please guide me how to solve this issue

2
have u tried it by providing parent_id in hash instead of full parent object.Aman Garg
no, but all the values are required for ArtifactImage table.Bathakarai
This is not right approach. How can you assign values with same keys multiple times in a hash like artifact_source_type_id. Its having two values nil and 3.Aman Garg
I am newbie to rails. So i don't know what approach it used in rails 2 and 3.Bathakarai
Paste the model code for ArtifactImage and ArtifactContainerAman Garg

2 Answers

1
votes

If you use acts_as_tree you can do this.

Coming from acts_as_tree or another system where you only have a parent_id? No problem. Simply add the lft & rgt fields as above, and then run:

Category.rebuild!

Your tree will be converted to a valid nested set. Awesome!:

In your case, you can try into:

ArtifactImage.rebuild!

More details documentation of acts_as_tree

0
votes

If you said in your comments that all the values are required for the ArtifactImage table, you need to ensure that all values are filled, which is not happening, since you have nil values. Instead of having those id values, can't you have a relation between objects? I would make more sense.