Rails: How to use a n:m association as 1:n association

A join model can enforce a single associated record when a foreign key on the target model is not possible; validates_uniqueness_of on the join row limits the relation to one.

How to use helper methods in a controller

Expose controller logic to views so helper-style methods can be called from templates, with different APIs in Rails 2 and Rails 3+.

How to set the user agent in tests

Customizing the User-Agent header in tests makes browser- and crawler-specific behavior reproducible across Rack::Test, Selenium, and request specs.

Spreewald: When using `patiently do`, don't reuse existing variable names

patiently do repeats a block until it passes or times out; reusing outer variable names inside the repeated block can make repeated evaluations fail.

def vs. define_method

Ruby’s def and define_method differ in scope, closure behavior, and how the receiver is chosen, affecting access to outer variables and method definition targets.

How to make Rational#to_s return strings without denominator 1 again

Ruby 1.9+ renders integer-valued Rational objects as 2/1, which can leak into views and date calculations. A small override restores the Ruby 1.8-style integer string output.

Test redirects to an external URL with Cucumber/Capybara

External redirects are awkward to test with Cucumber and Capybara: Rack::Test ignores the host, while Selenium follows it. Controller specs or an observable redirect make the target URL verifiable.

How to disable cookies in cucumber tests

Capybara has no built-in switch for disabling cookies in browser tests; a small Rack middleware can strip request cookies so scenarios can verify sign-in failures without them.

Cucumber step to set cookies in your Capybara session

Set browser cookies in Cucumber feature tests when you need to simulate visitors with existing cookie data across the full application stack.

Capybara 0.3.9 Bug: Chaining .find to scope doesn't work

Chaining find calls in Capybara can ignore the current scope, causing the second lookup to search the whole DOM instead of the intended element.

The Plight of Pinocchio: JavaScript's quest to become a real language - opensoul.org

JavaScript has become essential for production applications, but maintainable code still depends on structured design, object-oriented principles, and test-driven development.

What's in a View? A look at the alternatives

Tradeoffs between progressive enhancement with jQuery-style approaches and client-side views affect interactivity, complexity, and how much rendering stays on the server.

Ruby: Debugging a method's source location and code

Find where a Ruby method is defined and inspect its implementation; Method#source_location reveals file and line, while method_source can return the method body.

Initiate SSL secured TCP connections to remote services

telnet and nc cannot open SSL-secured TCP connections to remote services; openssl s_client can test the connection and handshake.

Chart.js - a promising JavaScript charting library with MIT-license

Lightweight canvas-based charting for web apps with high configurability and broad browser support. A permissive MIT-licensed alternative to Google Charts and commercial libraries.

Comparing Rails' flash hashes will not respect their internal lists of used entries

Rails FlashHash comparisons ignore the internal used-entry state, so two flashes can look equal even when their next-request behavior differs.

Fix „rvm no such file to load -- openssl“ or "rvm no such file to load -- zlib"

Missing system libraries can break RVM Ruby installs, causing no such file to load -- openssl or zlib errors. Reinstalling the required dependencies and recompiling Ruby fixes the issue.

Tips And Tricks For Print Style Sheets

Print output often loses links, QR codes, and image quality. CSS print styles can add link URLs, better graphics, and browser preview support.

Interactive generator for gradients, borders, noise textures and box shadows

Create CSS gradients, borders, noise textures and box shadows visually, then copy ready-to-use CSS or SASS output.

Browser Hacks: CSS Rules to Target Specific Browsers And Versions

CSS hacks can target specific browsers or browser versions to work around rendering bugs and compatibility issues without abandoning robust styles.

About progamming with Multi-Touch, Touch- and Mouse-Events in the webbrowser

Touch-capable devices make it important to handle mouse and touch input together in web apps, including multi-touch browser events.

Ruby 1.9 or Ruby 2.0 do not allow using shortcut blocks for private methods

&:test works for private methods in Ruby 1.8 but raises NoMethodError in Ruby 1.9 and 2.0.

Different behavior for BigDecimal#floor in Ruby 1.8 and Ruby 1.9

BigDecimal#floor returns different types in Ruby 1.8 and 1.9 because it depends on Float#floor; a backport restores the Ruby 1.9 behavior on Ruby 1.8.

How to copy your „Google Chrome“ or „Chromium“ profile without creating an online account

Moving a Chrome or Chromium profile to a fresh system is possible by copying the local profile directory instead of creating an online account.