Rails 2.3.3: Touching, faster JSON, bug fixes

Send to friend

We’ve released Ruby on Rails version 2.3.3. This release fixes a lot of bugs and introduces a handful of new features.

Active Record

  • touch is a convenient method to update a record’s timestamp and nothing else. This is extracted from apps whose models “touch” others when they change, such as a comment updating the parent.replies_changed_at timestamp after save and destroy. Timestamping an entire has_many association makes it easy to build a key for fragment caching that covers changes to the parent object and any of its children. This pattern is wrapped up as belongs_to :parent, :touch => :replies_changed_at. When the child changes, parent.replies_changed_at is touched. :touch => true is defaults to :touch => :updated_at.
  • :primary_key option for belongs_to for broader support of legacy schemas and those using a separate UUID primary key: belongs_to :employee, :primary_key => 'SSN', :foreign_key => 'EMPID' changeset

JSON

  • decoding backends for the json and yajl libraries. Both are significantly faster than the default YAML backend. To get started, install the json gem and set ActiveSupport::JSON.backend = 'JSONGem'.
  • leaner user-facing encoding API. Since a JSON libraries implement to_json with varying compatibility, safely overriding it is difficult. Most custom to_json looks like
    
    def to_json(*encoder_specific_args)
      { :some => "json representation" }.to_json(*encoder_specific_args)
    end

    so we DRYed the user-facing API down to a more natural

    
    def as_json(options = {})
      { :some => "json representation" }
    end

    without the ugly internal state exposed by overloading to_json as both public-facing and internal builder API. Rails 3 splits the API explicitly, so prepare now by switching from to_json to as_json.

Other Features

  • Add :concat option to asset tag helpers to force concatenation. changeset
  • Restore backwards compatibility for AR::Base#to_xml. changeset
  • Move from BlueCloth to Markdown for the markdown helper. Users using BlueCloth to provide their markdown functionality should upgrade to version 1.0.1 or 2.0.5 in order to restore compatibility.

Notable Bug Fixes

  • Fix errors caused by class-reloading with streaming responses in development mode.
  • Several fixes to the gem bundling, unpacking and installing system.
  • Make text_area_tag escape contents by default.
  • Make filter_parameters work correctly with array parameters.
  • Thread-safety fixes for postgresql string quoting.
  • Performance fixes for large response bodies.
CouchLog: Keep App Logs on the Couch | Rails Fire

CouchLog: Keep App Logs on the Couch

 CouchLog: Keep App Logs on the Couch

For the past 6 years we have developed many Ruby on Rails applications for clients from Chrysler to non-profits. Many of the applications we have built have been proprietary, and not publicly available. This has not allowed for us to release our work into the open source community. I’m happy to say that this is changing.

A recent project of ours is Local Digerati. For the technical elite who are looking to take full advantage of sales opportunities, Local Digerati is a site that helps you find trusted locals you can team up with on projects, and take on more business. Unlike using search engines and directories, our product allows you connect with the highest quality, most trusted people close to you.

Enough with the pitch already.

With Local Digerati, we’re using all the latest hotness from the Ruby on Rails community, and creating some of our own, all of which we are going to open source. The first project coming out of Local Digerati is CouchLog. CouchLog is a little plugin that puts all of your Rails application logs into a CouchDB database, rather than keeping them on disk. It also adds some additional fields – timestamp and log level – to each entry.

So why keep logs in CouchDB rather than the log files?

Have you ever had to read log files to see what’s going on in your app? How is log rotate working out for you? What about custom metrics and data mining applications? Having the log files in CouchDB allows the leveraging of Couch’s features like database replication, so you can easily run a metric app against a copy of the database rather than parsing the production logs.

CouchDB is a document database, which means that there is no schema. For CouchLog this is great, as you can customize the plugin by adding additional information to your log entries and not have to worry about running schema migrations. Easy peazy.

CouchLog is currently under development  (meaning you don’t want to use it yet), and should be production ready soon.

Enjoy!