On 12/15/10 12:40 PM, Finne Jager wrote:
Just another quick question if you don't mind.
I'm trying to manually append a SafetyOfficer to the Timesheet with the
Rails console:
Incident.first.timesheet.safety_officer<< SafetyOfficer.last
This is pulling just the first record found of incident so its an object
of Incident with an associated object of timesheet with an associate
object of security_officer. You need to have an array for this as you
are appending an object to an array.
It looks like an incident has 1 time sheet and that a timesheet should
have many security officers, so that should be plural.
Incident.first.timesheet.safety_officers << SafetyOfficer.last
You will want to make sure that you are using a join for this and it
would be best to have this action in the join table's create action,
IMHO at least.
If this is not what you are looking to then maybe some more detail as to
what you are trying to accomplish would help.
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.<<
I searching for a solution but can't find anything. Do you know what
this error message means? All the fields in SafetyOfficer.last are
correct, and 'timesheet_id' is 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 rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.