Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11541 (new defect)

Opened 1 month ago

type_name_with_module breaks when parent.class == type

Reported by: maurocicio Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: normal Keywords: type_name_with_module namespace module
Cc:

Description

module Forum
  class Post < ActiveRecord::Base
    acts_as_tree :order => 'created_at'
  end
end
$ ./script/console 
Loading development environment (Rails 2.0.2)
>>  Forum::Post.create().children.create()
ArgumentError: Forum is not missing constant Post!

The problem seems to be that type_name_with_module('Forum::Post') returns 'Forum::Forum::Post' instead of the expected 'Forum::Post'

I am using the following now, and things seems to work all right:

def type_name_with_module(type_name)
  (/^(#{parent.name})?::/ =~ type_name ? type_name : "#{parent.name}::#{type_name}"
  # Original code
  #(/^::/ =~ type_name) ? type_name : "#{parent.name}::#{type_name}"
  end