Monthly Archives: June 2009

Named_scope clashing with ActiveSupport

One of the named_scope defined by Station was parents. It simply scoped searches in Resources to records that haven’t a parent_id defined. This is useful for Posts or AttachmentFu records (which makes thumbnails with the parent_id).

The name “parents” was unfortunate, as it clashes with a method in ActiveSupport::CoreExtensions::Module

So the named_scope has been renamed to “parent_scoped“. You are encourage to upgrade to the new stable version, Station 0.2.3

Advertisements

Getting several AR objects in one query: ActiveRecord::Content::Inquirer

There are some issues already included in Station I want to blog, because I think they are interesting.
One of them is ActiveRecord::Content::Inquirer

In Station, a container is an ActiveRecord model that have many contents, like posts, images, videos, bookmarks, etc.. What if you want to obtain all the contents in a Container using just one SQL query? And you also want to paginate them? And, of course, getting back instances of every Content!

ActiveRecord::Content::Inquirer does just this. You use it:


ActiveRecord::Content::Inquirer.all :container => somespace,
                                    :page => params[:page],
                                    :per_page => 10

It even accepts an Array in :container.

Some of the magic is under this hack:


class Inquirer < ActiveRecord::Base
  @colums = Array.new
  @columns_hash = { "type" => :fake }


  ...
end

This way, it’s possible to use ActiveRecord::Base goodies without a real table in the database.

Initializing…

I’ve opened this blog to write about Rails Station development.

Station is a Rails Engine (a plugin with app/, routes and more) focused on Content Management. Station provides your Rails application with a CMS framework, this means authentication, authorization, categories, tags, etc…

This development is part of the work in my Ph.D thesis, which is about distributed social software, so I plan to add more features following that way.