DateTimes are Dates, beware

Posted About 11 years ago by dncrht.

datetime = DateTime.now date = datetime.to_date #or Date.today will assert: datetime.is_a? Date == true datetime.is_a? DateTime == true datetime.instance_of...

When you set date attributes, you should not pass times

Posted About 11 years ago by Arne Hartherz.

As you know, time zones make stuff a bit more difficult but are necessary. A time-zoned record is converted...

Profiling Ruby with ruby-prof

Posted Over 11 years ago by Nasir Jamal.

require 'ruby-prof' # you don't need this if you have ruby-prof in your Gemfile You can set one...

has_defaults issues

Posted Over 11 years ago by Dragos Miron.

The object returned by has_defaults apparently is the same between multiple object creations. Consider this scenario:

Database: Scopes, migrations, and indices

Posted Over 11 years ago by Julien Letessier.

Wether you modify an existing named scope or add a new one, or when you write a new query, make...

Cleaner Rspec

Posted Over 11 years ago by Nasir Jamal.

When simply checking equality or truthiness then Instead of: it "should have role set to admin" do @user.role.should eql('admin...

Method return value should always be of same type

Posted Over 11 years ago by Nasir Jamal.

One of the main source of bugs and complexity in the code is when a functional method (that we expect...

Add indexes on foreign keys when you create a migration (with foreign key)

Posted Over 11 years ago by Dragos Miron.
tomafro.net

Whenever you make a migration to add a foreign key, you should also add an index for it

Creating a gem in lib folder

Posted Over 11 years ago by fragalla.
github.com

Go to lib folder and use bundler to generate main files for a gem: $ bundle gem test_gem create test...

Rebase your feature branches

Posted Almost 12 years ago by Arne Hartherz.

Regularly, but at least before merging your feature branches, rebase them to get rid of "fix typo" and "wip" commits...

ActiveRecord::NamedScopes (2.3.x) obtaining the SQL conditions

Posted Almost 12 years ago.

It's a good pratice to chain several named scopes like: Property.listable.for_2_or_more_guests.best_10_properties Now, to make the lesson more...