Donate to charity: water via Gittip

obviously

Guess obvious association class names in ActiveRecord.

Makes using namespaced model names, like Project::Discussion, much less painful.

Installation

Add this to your Gemfile:

gem 'obviously'

Usage

Notice the lack of class_name: 'User::Membership' style options in the associations. Works with belongs_to, has_one and has_many:

class Project < ActiveRecord::Base
    class Attachment < ActiveRecord::Base
        belongs_to :discussion
            # class_name: 'Project::Discussion'
    end

    class Discussion < ActiveRecord::Base
        belongs_to :project

        has_many :attachments
            # class_name: 'Project::Attachment'
    end

    has_many :discussions
        # class_name: 'Project::Discussion'

    has_many :attachments,
        through: :discussions
        # class_name: 'Project::Attachment'
end