What a time saver
We have a project that has a few associations starting with user.
The User has many project and projects has many stopwatches.
We were working on a clean solution that would allow a user to directly edit a stopwatch.
However, we wanted to make sure that the user only edits his or her stopwatches.
So rather than passing a hidden field with the project_id, or using a virtual atribute to save the updated data for the stopwatch, we found a great plugin that allows you to bunny hop over associations.
The Nested Has many Through plugin lets you do:
@stopwatch = current_user.stopwatches.find(params[:id])
This is absolutely fantastic because in reality the association is:
So basically, the plugin does the work of finding and loading the project to you can go directly to the current_user's stopwatch.
Now, that being said, we might just port the site to MongoDB so that the stopwatches are an array on the project document, but the plugin is still very cool nonetheless.
*Note: if you are using rails 2.3x, use the 2.3 branch of the plugin.