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...

makandra dev

Update RubyGems and Passenger Bundler requires Rubygems >= 1.3.6. Run gem update --system if you have an older version.

Sometimes you want to fetch associations for an ActiveRecord that you already loaded, e.g. when it has deeply nested associations...

When working with times and dates in Rails applications, you need to deal with the following problem: In Rails, Time...

github.com

jamesgolick / resource_controller at Github module ResourceController module Actions def index load_collection before :index response_for :index end

When doing a query like this: SELECT id FROM users WHERE (users.id IN (899,1084,1095,100,2424,2429,2420...

github.com

An alternative to this technique is using VCR. VCR allows you to record and replay real HTTP responses, saving you...

In a nutshell: to avoid your shell character set from messing with imports, use -r to export and SOURCE when...

ALTER DATABASE database_name CHARACTER SET "utf8"; ALTER DATABASE database_name COLLATE "utf8_unicode_ci"; After that, for...

github.com

Ancestry is a gem/plugin that allows the records of a Ruby on Rails ActiveRecord model to be organised as a...

makandra dev

This may be awkward to set up, but will work once you're done. Fun facts:

Unless all MySQL server defaults are set to UTF-8, mysqldump encodes UTF-8 characters incorrectly and only outputs correct...