When a has_many association basically serves to store a list of associated strings (tags, categories, ...), it can be convenient...
When you just went through a long debug-fest and infested your code with dozens of debug messages, it can...
Occasionally some complex query must be processed on the database because building thousands of Ruby objects is impracticable.
When you use will_paginage to paginate a scope, and you want to obtain the total number of records matched...
You most likely never want to do this. But if you do: Model.update_all({:id => new_id}, {:id => old_id...
As a user of Bundler you have spent significant time looking at this message: Fetching source index for http://rubygems.org...
Use this scope: class Stick named_scope :shuffled, lambda { last_record = last { :conditions => [ 'id >= ?', rand(last_record.id) ] } if last_record }
CONCAT('foo', 'bar', NULL) = NULL the NULL always wins in MySQL. If you would rather treat NULL as...
Use this MySQL command to show further info about a table: SHOW CREATE TABLE tags; This will output a table...
If a controller action responds to other formats than HTML (XML, PDF, Excel, JSON, ...), you can reach that code in...
If you want to see how long your database queries actually take, you need to disable MySQL's query cache...
It can be useful to have a Ruby expression like condition ? positive_case : negative_case in MySQL queries:
When you need to delete rows from a table, and the delete conditions require a joined table, MySQL needs to...
You can use record.send(:update_without_callbacks) or record.send(:create_without_callbacks) This can be used as a...
For some reason you want to define a find condition in array form. And in that condition both column name...
Find conditions for scopes can be given either as an array (:conditions => ['state = ?', 'draft']) or a hash (:conditions => { 'state' => 'draft...
There are many different methods that allow mapping an Array to a Hash in Ruby. Array#to_h with a...
When Paperclip attachments should only be downloadable for selected users, there are three ways to go. The same applies to...
In modern Rails versions you can also use ActiveRecord's pluck method. User.active.pluck(:id) => [1, 5, 23, 42]
You should test the callback methods and its correct invocation in two separate tests. Understand the ActiveRecord note before you...
When you load a record with find options that have SQL fragments in :select or :joins, ActiveRecord will make that...
Embedded Flash movies do not always obey element order and z-index. To fix this, set the wmode attribute to...
If you iterate over a collection of arrays, you can destructure the arrays within the block parameters: movies_and_directors...
The state_machine gem ships with a scope with_state. This scope has some problems in complex queries or scope...