More Rails Superstition

A few quirks I've run across in Ruby on Rails 1.1

Posted by 04/05/2006

Some coding challanges I've recently faced working with Ruby on Rails - and how I worked around them. Whether they were real problems, or just imaginary, superstitious work arounds is unclear.

Namespacing seems to work as of RoR 1.1. This is good because it makes housing multiple applications in a single Rails instance much easier. I'm working on a project now that is 3 different projects for one unit. So they share models like "User", but also have their own "Project" models that are wildly different. So I'm using namespaces to categorize the projects for each unit, but I need some of the relations to attach to global models.

I have run into a few quirks though. Whether they are real, or only superstitions I don't know.

Given this:


module Communications
    class BaseRecord < ActiveRecord::Base
    end
end

and

module Communications
    class User < BaseRecord
    end
end

I thought I could do something like this:

module Multimedia
  class Project < Communications::BaseRecord
    belongs_to :user, :class_name =>"Communications::User"
  end
end

That didn't work though. I got this message:

`const_missing': uninitialized constant Communications

However if I do this:

module Multimedia
    class User < Communications::User
    end
end

coupled with this:

module Multimedia
  class Project < Communications::BaseRecord
    belongs_to :user
  end
end

it will work. It is close enough for me, and I actually prefer subclassing within the module - but I could see someone getting annoyed with this.

Comments

Post a comment


Total: 0.19 Python: 0.18 DB: 0.02 Queries: 31