Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Standup 10/28/08

Rajan Agaskar
Tuesday, October 28, 2008

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.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

3 Comments

  1. Josh Knowles says:

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

    October 28, 2008 at 5:48 pm

  2. Brandon Keepers says:

    Just to clarify, [filters](http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html) (used in controllers) and [callbacks](http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html) (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.

    October 28, 2008 at 7:29 pm

  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.

    http://intridea.com/2008/4/20/seed-fu-simple-seed-data-for-rails

    http://github.com/mbleigh/seed-fu/tree/master

    October 28, 2008 at 8:04 pm

Add New Comment Cancel reply

Your email address will not be published.

Rajan Agaskar

Rajan Agaskar
San Francisco

Recent Posts

  • Restart post-migration
  • Capybara 2.0 is out.
  • Try using Mongo
Subscribe to Rajan's Feed

Author Topics

  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >