Hi,
I have 2 models 'item' and 'activity'. An 'item' can have many 'activities' (limited number of activities, used by all items). To make it clearer: this is represented by a table with one item per row, one activity per column and something/nothing on the intersection if a line exists in the table matrices.
to see an image (worth a 1000 words :)): http://tinypic.com/r/33ygtj9/3
The relationships are (i think) set correctly: item has_many matrices, item has_many activities through matrices
activity has_many matrices, activity has_many items through matrices
matrix belongs to item, matrix belongs to activity
Some additional/useful info: - the matrix is represented graphically by a table with one item per row, one activity per column and OK/KO on the intersection if a line exists in the table matrices. - i have 2 other models in the picture: a course model and a chapter model (course has many chapters, chapter has many items) - Everything happens in the Course 'show' view
So far, i've managed to directly create a line (without going through a form) in the matrices table with the activity_id and the item_id. However I struggle to delete a line, because I don't understand how to access the matrices.id value.
The only way i've found yet is, for each item, to loop through all available activities for this item in a hash (key = activity_id, value = matrices_id). If the activity is not available, i display OK + a link to create a line in matrices else,OK + link to destroy.
Is there an easier/more 'Rails' way to do that ? i.e. get rid of the hash?
thanks for your help.
Pierre