Having a problem initializing an associated table

Q. What am I doing wrong such that tx_batch_mtime is not receiving the
value I believe that I am assigning? At this point current_entry has
not itself been saved.

I have this code:

puts( “*** ***” *3 )

  current_log_entry = current_entry.edi_log_entries.build

puts( current_log_entry.class )
puts( hash[:current_batch][:tx_batch_mtime] )

  current_log_entry.tx_batch_mtime = \   # linebreak for clarity
    hash[:current_batch][:tx_batch_mtime]

puts( current_log_entry.to_yaml )
puts( current_entry.cctn )
puts()

Which produces this output:

  ***      ******      ******      ***
  CaCustomsEdiLogEntry
  1276181402
  --- !ruby/object:CaCustomsEdiLogEntry
  attributes:
    tx_batch_number:
    created_at:
    changed_by: " "
    tx_message_function:
    tx_record_type:
    tx_batch_date:
    lock_version: 0
    tx_batch_account:
    created_by: " "
    accessed_at:
    tx_batch_mtime:
    tx_message_data:
    changed_at:
    accessed_from: " "
    ca_customs_entry_id:
    accessed_by: " "
  attributes_cache: {}

  changed_attributes: {}

  destroyed: false
  marked_for_destruction: false
  persisted: false
  previously_changed: {}

  readonly: false
  13466600016294

  1276181402
  20100610
  13466
  009

As you can see, current_edi_log.tx_batch_mtime is nil whereas I expect
it to be 1276181402. Why?

On 7 February 2011 21:06, James B. [email protected] wrote:

puts( current_log_entry.class )
puts( hash[:current_batch][:tx_batch_mtime] )

current_log_entry.tx_batch_mtime = \ # linebreak for clarity

The \ must be the last char on the line, though I would have expected
this to generate a compile error.

If still not working use ruby-debug to break into the code and inspect
data to see what is going on. See Rails Guide on debugging if unsure
how to do this. I is often a lot easier than loads of debug o/p.

Colin

Colin L. wrote in post #980132:

On 7 February 2011 21:06, James B. [email protected] wrote:

puts( current_log_entry.class )
puts( hash[:current_batch][:tx_batch_mtime] )

current_log_entry.tx_batch_mtime = \ # linebreak for clarity

The \ must be the last char on the line, though I would have expected
this to generate a compile error.

The line break and comment exist only in the forum message because of
the way the forum wrapped the unbroken line found in the code.

I discovered the problem. mtime is a datetime attribute in the model
and an integer in the hash. So I required
Time.at(hash[:current_batch][:tx_batch_mtime]) for the assignment to
work.