Sometimes you might want to limit the number of associated records in a has_many association, but cannot add a...

view_context.helper_method('args') Rails 2 ApplicationController.helpers.helper_method('args') Also see How to use helper methods inside a model...

The way Rational#to_s works on Ruby has changed from Ruby 1.9 on. Here is how to get the...

When a controller action redirects to an external URL (like http://somehost.com/some/path) you will find that this is hard...

Unfortunately, Capybara does not offer a switch to disable cookies in your test browser. However, you can work around that...

stackoverflow.com

Access the Method object Dead simple: Get the method object and ask for its owner: "foo".method(:upcase) # => #

Rails flashes (FlashHash) track a list of used keys, which is not respected when comparing flash hashes.

Do not pass times to date attributes. Always convert times to dates when your application uses time zones. Background

Ruby 1.8 (supplied by Rails' ActiveSupport) >> BigDecimal.new("0.1").floor.class => BigDecimal Ruby 1.9 (supplied by Ruby 1.9 itself) >> BigDecimal.new("0.1").floor.class...

ariejan.net

Rails understands a :limit options when you create columns in a migration. Its meaning depends on the column type, and...

robots.thoughtbot.com

Guide how to make fixes in other people's GitHub repositories. It's basically "Open Source Development 101".

web.archive.org

TL;DR: You should generally use #size to count associated records. size Counts already loaded elements If the association is...

tl;dr: Do not use merge! for session hashes. Use update instead. Outline Let's assume you're modifying the...

Watch out when saying something like 1.year in Rails. The result is not a Fixnum and can cause unexpected errors...

github.com

MongoMapper is a MongoDB adapter for Ruby. We've forked it so it works for Rails 2.3.x applications running...

makandracards.com

See attached link for a way to extract the conditions of a named scope in Rails 2.3.

gist.github.com

Rails 2.3.16+ on Ruby 1.9 causes warnings like this: .../gems/activesupport-2.3.17/lib/active_support/core_ext/string/output_safety.rb:22: warning: regexp match /.../n against to UTF-8 string...

makandra dev

JavaScripts and CSS should be minified for production use. In Rails 3.1+ the asset pipeline will take care of this...

If you need to capture signatures on an IPad or similar device, you can use Thomas J Bradley's excellent...

You either have an old version of Mocha and an edge version of Rails 3.2, or you have a new...

makandra dev
rails-sqli.org

This page lists many query methods and options in ActiveRecord which do not sanitize raw SQL arguments and are not...

makandra dev
github.com

Stringex is a gem that offers some extensions to Ruby's String class. Ruby 1.9 compatible, and knows its way...

In our continued quest to extract proven code snippets from makandropedia into tested and upgradable gems, we have released Edge...

TLDR: Ruby class variables (@@foo) are dangerous in many ways. You should avoid them at all cost. See bottom of...