List-A-Task: A jacked up task lister by Matthew Billie
Dependencies:
bcrypt for secure passwords carrierwave for uploading avatars twitter-bootswatch-rails slate theme for layout postgresql database acts_as_paranoid for soft delete factory_girl_rails for test factories
Instructions:
Bundle install; rails server; make an account!
Features:
-
Lists, tasks, and stars are ajaxed for instant updates
-
Users can upload an avatar image for their show page
-
Soft delete for recoverable items for admin statistics
-
Admin portal with masquerade log in as any user
-
Test suite for models, controllers, and some features
-
Edit in place for task descriptions/priorities
-
Polymorphic Star class, lists and tasks can be starred or unstarred
-
Proper user/admin verification for all pages
I approached this first without javascript, building out the domain model, then creating the controllers, then views. Once everything was working without javascript, I added in all the ajax. This proved challenging, but through the use of data-id attributes I got everything ajaxed. Following this I added the image uploader, which was very easy with carrierwave. Next I added admin features. I wanted to have admin be able to log in as any user and also be able to return to their admin user without re-entering their information. To do this i used the log_in_as method that stores the admin user_id in session for later retrieval. I wanted statistics for total lists, tasks, and stars made, so I decided to implement soft delete via the acts_as_paranoid gem. This was a bit challenging, since the documentation is spare, but I got it all working and now have almost all the statistics I wanted on the admin page. The most difficult statistic was ‘total items starred for user’. The problem arose from the polymorphic association, but I did find a slightly messy work-around by finding all the starred lists, then selecting those with the proper user_id, I did the same for starred tasks, then combined their lengths to come up with total items starred for a user. I plan on looking in to delegation with polymorphism to solve this.
I decided to leave out respond_to format.html in my controllers, as I was having trouble getting my tests to pass with it included. Also, since I used remote true on almost every form, It would never submit if javascript was disabled. I do have a method that notifies about ajax errors, however.
My views are made up almost entirely of partials to allow them to render_to_string and be returned on ajax:success. In some cases, I am returning a json object with a partial object, an item_id object, and item object, or other objects in order to be able to append them properly to page, or in order to delete the appropriate elements from the page. I used several hidden fields for foreign_key ids in order to ensure objects would be built with the proper parent association.
Future plans include figuring out a better solution to ‘User#total_starred_items’, adding some advanced activerecord methods, hopefully figuring out a way to delegate a user to my polymorphic Star class, and creating custom css layouts for lists and tasks. I would also like to implement a Tag model for Lists, with a ListTags join table.
Hope you enjoy my roided up task lister!
— updates —
Refactored javascript to be object oriented Added many more user stats to admin page Added search tool with options and results filters to admin page Added model methods for admin stats/search Refactored some class methods for optimization