One line. 15 hours and all that stood between me and functionality was one line. I’d be mad if that didn’t happen so often. So what did happen? I had the code for ActiveRecord’s Multiparameter attributes on one screen, and I had mongoids old Multiparameter extension on the other. My original plan was to put a variation of ActiveRecord’s code into a monkey patch and then put it into mongoid if it work. But as I read the mongoid code more carefully, I found that while it was a little harder to read, it was a little more concise than the activerecord code.
In activerecord, you called the assign_attribute method, then if you had a multiparameter attribute you called the assign_multi_parameter_attributes method, then you executed the callstack which extracted the callstack, and then you determined the time zone, intstantiated the objects…
In Mongoid, you made sure the keys and values went into the right place, determined the class of the attributes you were working with, “mongoize” it, and relegate the rest of the logic to the superclass. Since that was slightly less incomprehensible, I decided to take another look at the module.
The tests were failing because Rails did not recognize the permit= method. I didn’t know yet just what this was for, so I commented the line out to see what would happen. I still got a forbidden attribute error from activemodel, so I figured that it had something to do with the strong parameters method in the controller. I tried permitting the split time attributes every which way I could with single quotes, double quotes, no quotes, but I was still getting this error. I took another look at the line with the permit = method that I had commented out. I looked up the method and found out that it had been deprecated in favor of the permit! method. Not only that, but it was being used on a new attributes object that had been instantiated within the module. I changed permit = true to permit! and it worked!
Even though I just made I tiny modification to one of Mongoid’s deprecated module’s, I’m still going to try and put it back in through a pull request. Why? Just because that issue took up so much of my time doesn’t mean it has to ruin anyone else’s day. The gem shoudl work as advertised, or at least as documented! Also, I still don’t really know why there were so many issues with the module in the first place. This might be the best way to find out! And finally, hopefully, we can do something about those failing friendship tests today.