Freeze a specific Rails version
sudo apt-get install unzip
rake rails:freeze:edge RELEASE=2.2.2
Ruby: How to make your ruby library configurable
Configuring a Ruby library via a block makes endpoints and similar settings easy to override without hardcoding values.
JavaScript without jQuery
Moving away from jQuery improves performance, reduces bundle size, and aligns with the modern web platform. Native DOM APIs and polyfills now cover most common needs.
RSpec: Where to put custom matchers and other support code
Custom RSpec matchers and support code need a clear home in spec/support to keep specs DRY and make shared helpers available everywhere.
How to discard ActiveRecord's association cache
ActiveRecord association data can stay stale after changes; reset clears the cache without querying, while reload fetches fresh rows immediately.
How to eager load a single directory with Zeitwerk
Zeitwerk can eager load a single subdirectory so descendant classes are available for iteration, while avoiding manual require of the parent file.
When using "render :text", set a content type
Rails render :text responses default to text/html, which is wrong for plain text and can trigger HTML middleware; set content_type or use render :plain.
The Ruby Object Model
Ruby’s object model can be confusing for developers from static languages. Objects, singleton classes, and modules shape method lookup, class methods, and inheritance.
Defining custom RSpec matchers
Custom RSpec matchers support reusable test assertions, chaining, block expectations, and complex matcher classes for domain-specific checks.
Rails: Have different session secrets for all environments
Using the same Rails session secret in staging and production can let a cookie from one environment authenticate in another. Separate secrets per environment reduce session hijacking risk.
Make Nokogiri use system libxml2
Nokogiri can be built against system libxml2 instead of bundled binaries, reducing rebuild work after security updates and aligning installs with patched OS libraries.
Capybara: Testing file downloads
File downloads are awkward to verify with Selenium because browsers may prompt, auto-save, or render binaries instead of HTML. Alternative approaches use request specs, Rack::Test, or the browser download folder.
Beware when using ActiveSupport time and date calculation methods
Duration#ago and Duration#from_now return ActiveSupport::TimeWithZone, which can introduce unexpected timezone behavior when an app assumes local or timezone-unaware dates.
Setup Sidekiq and Redis
Sidekiq needs a Redis connection configured separately for client and server environments. A REDIS_URL constant and startup load path keep staging, production, and test settings consistent.
Why developers should be force-fed state machines
Most web applications contain several examples of state machines, including accounts and subscriptions, invoices, orders, blog posts, and many more. The problem is that you might not necessarily think of them as state machines while designing your application. Therefore, it is good to have some indicators to recognize them early on. The easiest way is to look at your data model.
Matching elements on complex web pages with Webrat
XPath matchers can be combined with CSS-selector matchers. This is really useful if not, for example, the content of an element should be matched but the element itself like in the following example. Here a form is used to display data as default value in its input elements. This can be the case in web applications in which data should be edited easily without additional clicks.
PostgreSQL cheat sheet for MySQL lamers
Quick PostgreSQL command equivalents for MySQL users switching databases, listing tables, managing roles and privileges, and loading dumps.
Ruby: A small summary of what return, break and next means for blocks
return, break, and next behave differently in Ruby blocks: one exits the method, one exits the yielding method, and one skips only the current iteration.
Heads up: pg_restore --clean keeps existing tables
pg_restore --clean removes data from dumped tables but leaves extra tables in place, which can break later migrations when restoring a staging dump locally.
Custom Ruby method Enumerable#count_by (use for quick statistics)
Quick statistics on collections often need grouping, counting, and sorting. Enumerable#count_by combines them for flexible Ruby-based frequency counts beyond database columns.
Sending newsletters via rapidmail with SMTP and one-click unsubscribe
Newsletter delivery via SMTP with rapidmail, plus Gmail-compatible one-click unsubscribe using signed tokens and List-Unsubscribe headers.
Make your Rails console (and irb) output better readable
Colorized, structured output in Rails console and irb makes long strings, objects, and classes easier to inspect. awesome_print adds the ap command for readable formatting.
Faking and testing the network with WebMock
Network-dependent tests can avoid real HTTP by stubbing remote responses and asserting requests with WebMock, including query strings and bodies for GET and POST.
Git: Restore
git restore reverses staged, unstaged, deleted, or conflicted changes with clearer intent than git checkout, and can restore files from other revisions.