You most likely never want to do this. But if you do: Model.update_all({:id => new_id}, {:id => old_id...
To only run the next two migrations: rake db:migrate STEP=2 To revert the previous two migrations:
Use this scope: class Stick named_scope :shuffled, lambda { last_record = last { :conditions => [ 'id >= ?', rand(last_record.id) ] } if last_record }
Use this MySQL command to show further info about a table: SHOW CREATE TABLE tags; This will output a table...
You can now add an :inverse_of option to has_one, has_many and belongs_to associations.... Without :inverse_of...
You will need to upgrade to RSpec >= 2 and rspec-rails >= 2 for Rails 3. Here are some hints to...
If you previously used version 2.x of Thunderbird and upgraded to 3.x (for example through an Ubuntu release...
The ancestry gem allows you to easily use tree structures in your Rails application. There is one somewhat unobvious pitfall...
If you need to look at the list of methods that are called upon certain events (like before/after saving etc...
If you get an ActiveRecord::RecordNotSaved error, a method inside one of your model's callback chains (before_save etc...
When you do tags with acts-as-taggable-on and want to preload associated tags, you can do so with...
If you want to see how long your database queries actually take, you need to disable MySQL's query cache...
Hooks lets you define hooks declaratively in your ruby class. You can add callbacks to your hook, which will be...
Note that you should disable the Java plug-in in your browsers after installation. Ubuntu >= 12.04 Java 11
You can use record.send(:update_without_callbacks) or record.send(:create_without_callbacks) This can be used as a...
Find conditions for scopes can be given either as an array (:conditions => ['state = ?', 'draft']) or a hash (:conditions => { 'state' => 'draft...
When using virtual attributes, the attached trait can be useful to automatically copy errors from one attribute to another.
power-rake db:migrate VERSION=20100913132321 By default the environments development, test, cucumber and performance are considered...
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...
You can use the whatlanguage gem to detect the language of a Ruby string. Note that it also has not...
When you load a record with find options that have SQL fragments in :select or :joins, ActiveRecord will make that...