Copying validation errors from one attribute to another

Posted Over 13 years ago by Henning Koch.

When using virtual attributes, the attached trait can be useful to automatically copy errors from one attribute to another.

Run a rake task in all environments

Posted Over 13 years ago by Henning Koch.
youtube.com

power-rake db:migrate VERSION=20100913132321 By default the environments development, test, cucumber and performance are considered...

Deliver Paperclip attachments to authorized users only

Posted Over 13 years ago by Henning Koch.

When Paperclip attachments should only be downloadable for selected users, there are three ways to go. The same applies to...

Collect all values for a given column in an ActiveRecord scope

Posted Over 13 years ago by Arne Hartherz.

In modern Rails versions you can also use ActiveRecord's pluck method. >> User.active.pluck(:id) => [1, 5, 23, 42]

Testing state_machine callbacks without touching the database

Posted Over 13 years ago by Henning Koch.

You should test the callback methods and its correct invocation in two separate tests. Understand the ActiveRecord note before you...

Detect the language of a string

Posted Over 13 years ago by Arne Hartherz.
github.com

You can use the whatlanguage gem to detect the language of a Ruby string. Note that it also has not...

Understand ActiveRecord::ReadOnlyRecord error

Posted Over 13 years ago by Henning Koch.

When you load a record with find options that have SQL fragments in :select or :joins, ActiveRecord will make that...

Automatic Flushing: The Rails 3.1 Plan « Katz Got Your Tongue?

Posted Over 13 years ago by Lexy.
yehudakatz.com

This post explains, in some detail, how we will implement a nice performance boost for Rails developers. Understanding the details...

Efficiently add an event listener to many elements

Posted Over 13 years ago by Henning Koch.

When you need to add a event listener to hundreds of elements, this might slow down the browser. An alternative...

How Rails and MySQL are handling time zones

Posted Over 13 years ago by Tobias Kraze.

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

Default implementation of resource_controller actions

Posted Over 13 years ago.
github.com

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

Order for SELECT ... IN (5,100,23) queries

Posted Over 13 years ago by Thomas Eisenbarth.

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

Faking and testing the network with WebMock

Posted Over 13 years ago by Henning Koch.
github.com

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

Change default size of Gnome terminal

Posted Over 13 years ago by Henning Koch.

Open the configuration file: gksudo gedit /usr/share/vte/termcap/xterm Find a line like this: :co#80:it#8:li#24:\

Dumping and importing from/to MySQL in an UTF-8 safe way

Posted Over 13 years ago by Henning Koch.

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

UTF-8ify an existing MySQL database

Posted Over 13 years ago by Henning Koch.

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

jeremyevans's home_run at master - GitHub

Posted Over 13 years ago by Lexy.
github.com

home_run is an implementation of ruby’s Date/DateTime classes in C, with much better performance (20-200x) than...

stefankroes's ancestry at master - GitHub

Posted Over 13 years ago by Lexy.
github.com

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

MySQL replication how-to

Posted Over 13 years ago by Arne Hartherz.

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

MySQL Server and UTF-8 Defaults

Posted Over 13 years ago.

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

Test concurrent Ruby code

Posted Over 13 years ago by Tobias Kraze.

To test concurrent code, you will need to run multiple threads. Unfortunately, when you use blocking system calls (e.g. locks...

Concurrent Tests

Posted Over 13 years ago by Lexy.

Install gem and plugin sudo gem install parallel script/plugin install git://github.com/grosser/parallel_tests.git Adapt config/database.yml test: database: xxx_test<%= ENV...

Convert Haml to ERB

Posted Over 13 years ago by Henning Koch.

This is about converting Haml to ERB and not the other way round which you probably want! This process can...

How to install the date_performance gem

Posted Over 13 years ago by Henning Koch.

sudo gem install zip git clone git://github.com/rtomayko/date-performance.git cd date-performance rake package:build cd dist sudo gem install...