-
Rails Forms and Request Parameters
Sometimes in our Rails applications we need to build forms that represent state stored in URL query parameters that is independent of any persisted object in our backend datastore, like in the case of a search form. In this post I offer a simple, flexible, generic helper for doing just that.
Continue reading … -
Flattening Nested Hashes in Ruby
Sometimes, especially when working with external data, you will be handed a thickly nested blob of JSON, represented in Ruby as a nested hash. I have found in my experience that processing this data is often simpler when we can work with a flat hash instead, collapsing the key paths into a simple array key. And so, I wrote a function that does just this – it flattens a nested hash into a flat hash.
Continue reading … -
Expecting Exceptions in Ruby
Sometimes in Ruby code, having to use the
Continue reading …begin ... rescue .. endconstruction to capture and deal with exceptions can feel overly burdensome. I recently found myself in such a situation and wrote a small function to make my code read a bit more elegantly. -
Safely Accessing Values from Nested Hashes (again)
Implementing a companion method to
Continue reading …Hash#digthat always returns a value and never throws an error and allows for a default return value. -
Basic RESTful Filtering with Rails
Filtering a collection of data objects into a subset is one of the most common tasks in data-management applications. While well-tread, this problem space provides rich opportunity for exploring and learning about how to implement RESTful, maintainable, flexible, and robust Rails applications. In this post I want to implement a simple filtering feature, walking through the various aspects at the model, controller, and view layers.
Continue reading … -
An interlude with minitest/autorun
An interlude in a series of posts laying out the process, step by step, of building an interpreter in Ruby for working with propositional logic. In this small post, we take our hand-rolled "tests" and move the code into an executable test script with
Continue reading …minitest/autorun. -
Proper Propositional Logic
The second in a series of posts laying out the process, step by step, of building an interpreter in Ruby for working with propositional logic. In this second post, we expand the interpreter to handle the full range of valid expressions in classical propositional logic.
Continue reading … -
Starting Simple
The first in a series of posts laying out the process, step by step, of building an interpreter in Ruby for working with propositional logic. In this first post, we build an interpreter for working with simple logical expressions and dig into the specifics of the parts of an interpreter as well as the basics of propositional logic.
Continue reading … -
Time in Ruby and ActiveRecord
How does the Ruby
Continue reading …Timeclass relate to the ActiveRecordtimecolumn type? -
Typecasting in Ruby and Rails
I recently had the need to typecast string values passed as query parameters to a controller action to their appropriate type. In solving this problem, I've learned a lot about Rails' typecasting layer, Ruby's typecasting methods, as well as a handful of edge cases. The result was a typecasting function that I think has a lot to offer.
Continue reading …