Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

  • Blog Navigation
Standup 10/28/08

Interesting Things

  • before_save and after_save may not perform as you expect!

Previously, returning false from before or after filters callbacks would halt the chain entirely. This is no longer the case, except with before_save and after_save — returning false in a before_save will stop the filter callback chain and prevent a save, returning false in an after_save will stop the filter chain silently, and NOT rollback the save. This can be troublesome if you have after_save filters callbacks you expect to execute, especially if you have conditional clauses in an after_save, as they can easily return a false value where you did not intend it.

Please see Brandon Keepers’ clarification regarding filters vs. callbacks below — thanks Brandon!

Ask for help

  • Bootstrapping data into an existing system?

Using migrations for one-time data inserts can be problematic (for example, when changing seed data; additionally, it’s advisable to create a database from the schema.rb rather than migrations) , it can be useful to create a class that is responsible for inserting the seed data into the database. This class can be wrapped in a capistrano or rake task. The db-populate plugin is designed to aid in this task.

  • Multiple Routes/One controller

It is possible to point multiple routes at a single controller, however, this situation may suggest a need for multiple controllers, possibly inheriting from a single base controller containing any shared logic. This prevents a excessive switching logic in controllers, which can help minimize the possibility of argument-related bugs.

  1. Josh Knowles says:

    Thanks for the shout-out for db-populate. The code-base have moved to GitHub, and can be found at That said its a very simple plugin and nothing has changed from the version on Google Code linked above.

  2. Just to clarify, [filters]( (used in controllers) and [callbacks]( (used in models) are different. Filters no longer care what value is returned. They will abort the original request if the filter renders or redirects. On the model, if any before callbacks (`before_save`, `before_validation`, etc) return false, the save is aborted. If any “after” callbacks return false, the record is still saved to the database, but no other after callbacks are called.

  3. Cristi Balan says:

    I’ve been using seed-fu for quite a while and it’s pretty handy. It can even insert-only some fields so you can even use it for production data.

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *

Share This