Expressive Record

Express your changes

ActiveRecord 2.1 introduces dirty changes; the ability to query a model object to track attribute changes before the record is saved using #changes, #changed, etc.

However, belongsto associations are cached simply as foreign key changes, so Ticket#changes yields something like {"statusid" => ["111", "222"]}, which isn’t especially helpful when rolling your own ticket history mechanism.

  class Ticket < ActiveRecord::Base
    include ExpressiveRecord

    has_many :ticket_changes

    express_changes :ticket_changes

  end

Visit github for more info.

Continue Reading…

Posted by Luke on Nov 17, 2008

Class-level methods in Rails production

If you're using code this like this in your Rails controllers:


  before_filter :authenticate

  def authenticate
    User.current = User.find(session[:user])
  end

Be careful. Remember that the default Rails production environment differs from development in a very significant way: classes are cached. Might not seem like much at first, but remember that your User class is an instance of class Class, meaning that it's an object just like all other objects. But now, in production, you have a cached instance variable... and it has to be explicitly nullified after each each request, maybe with something like:


  around_filter :authenticate

  def authenticate
    User.current = User.find(session[:user])
    yield
    User.current = nil
  end

Continue Reading…

Posted by Luke on Sep 11, 2008 0 Comment(s)

patch rails sql server odbc driver

patch ODBCColumn with alias_method_chain

Here’s a quick-fix if you’re using the ODBC Adapter for Active Record gem/plugin and are getting errors with rake db:migrate when your schema includes a sql server sql_variant.

Continue Reading…

Posted by Luke on Mar 28, 2008

rails-mssql-tools update(rev. 10)

maintenance update

rev. 10 committed with:

svn ci -m "check for missing routines path; catch AR::StatementInvalid errors and send original error to STDOUT"

Posted by Luke on Mar 28, 2008

intermingle RJS partial rendering and raw javascript

wrap partial rendering in javascript

What I need is the ability to seamlessly send the contents of a partial to the client using the convenience of RJS, but wrapped inside a hand-written javascript condition (if some element exists, then update an element with this partial).

  # RJS template
  page << "if ('some_element_exists') {// page.replace_html using a partial}"

Continue Reading…

Posted by Luke on Mar 16, 2008 7 Comment(s)

mapperly

“Google maps, geocoding, and search-by-zip made easy”

Have a look at mapperly, my latest RoR project which mixes together several Rails plugins I’ve been wanting to try out.

Continue Reading…

Posted by Luke on Jan 04, 2008