Use ActiveSupport autoloading outside of Rails
The following code activates autoloading using ActiveSupport 3.x:
require 'active_support'
require 'active_support/dependencies'
relative_load_paths = %w[app/controllers app/models]
ActiveSupport::Dependencies.autoload_paths += relative_load_paths
Related cards:
Rails: How to get the ordered list of used middlewares
Rails middlewares are small code pieces that wrap requests to the application. The first middleware gets passed the request, invokes the next, and so on. Finally, the application is invoked, builds a response and passes it back to the last middlew...
What edge_rider offers you
edge_rider is Power tools for ActiveRecord relations (scopes). Please note that some of the functions edge_rider provides have native implementations in newer rails versions.
Useful in applications
Relation#traverse_association(*names)
---...
Use Memoizer instead of ActiveSupport::Memoizable
ActiveSupport::Memoizable
will be removed from Rails and has a lot of strange caveats that wil...
Use the contents of a WordPress database in your Rails app
These two models can be used to access the posts and associated comments of a WordPress database.
Comparing Rails' flash hashes will not respect their internal lists of used entries
Rails flashes (FlashHash
) track a list of used keys, which is not respected when comparing flash hashes.
This does not concern you under most circumstances.
Basics
When ActionController
picks up a flash object, it will call the #sweep
m...
Collection of Rails development boosting frameworks
Development environment setup
Rails Composer
: Basically a comprehensive Rails Template. Prepares your development environment and lets you select web server, template engine, unit and integration t...
Unpoly + Nested attributes in Rails: A short overview of different approaches
This card describes two variants, that add a more intuitive workflow when working with nested attributes in Rails + Unpoly.
Example
For the following examples we use a simple data model where a user has zero or more tasks.
class Examp...
Security issues with hash conditions in Rails 2 and Rails 3
Find conditions for scopes can be given either as an array (:conditions => ['state = ?', 'draft']
) or a hash (:conditions => { 'state' => 'draft' }
). The later is nicer to read, but has horrible security implications in some versions of Ru...
Rails and Postgres: How to test if your index is used as expected
This is a small example on how you can check if your Postgres index can be used by a specific query in you Rails application. For more complex execution plans it might still be a good idea to use the same path of proof.
1. Identify the...
Fix warning: Cucumber-rails required outside of env.rb
After installing Bundler 1.1 you will get the following warning when running tests:
WARNING: Cucumber-rails required outside of env.rb. The rest of loading is being defered until env.rb is called.\
To avoid this warning, move 'gem cucumber-...