Every once in a while we’d win. Now let’s not get carried away, it would only be a few dollars every once in while. Occasionally, as much as $10. We had decided that any “modest” winnings would be re-invested as extra tickets for the next draw.
So I needed to provide a mechanism for adding “bonus” picks. I’d already made allowance for this in my model, by providing a boolean “perm” column, which indicated whether or not a row of picks was part of the permanent collection. I already had the mechanism for input from the view, using the rails <% form tag %>
, all I needed to do was extend that to provide a multi-line input field. Easily done. And to add the code in the controller to iterate through each line and add the temporary picks to the database. Again, easy to do with text parsing and splitting on a carriage return line-feed, before reloading the page, all from within the controller. One small thing to look out for was that the “params” were passed as an array, therefore I need to access the zero index element in the action.
Not a huge increase in functionality, but satisfyingly easy to implement and deploy. The complement to these new functionality, was add another button to erase any temporary picks from the database, which was literally a single call to destroy_all
for any non “perm” rows.
Great! Now how about the annoying task of having to enter the twice-weekly draw. Time to research some URI and HTML parsing.