views:

20

answers:

0

I'm moving some code from being pulled in via SVN's externals function to be part of the code base proper. It's all Rails plugins and doing this seems to have broken part of my code.

It seems like Rails is misinterpreting a :belongs_to statement. I have belongs_to :target :polymorphic => true in one of my classes and previously that has done what it's supposed to and gone to the database to get the id of the target item and the more importantly the class of the item.

It doesn't seem to do that now. It seems to think that Target is the class and goes off looking for target.rb which doesn't exist.

Did I somehow break :polymorphic?

Here's the error:

FATAL NameError (Constant Target from target.rb not found):
desert (0.5.3) lib/desert/rails/dependencies.rb:15:in `load_missing_constant'
/Applications/WebStack/opt/local/lib/ruby/gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
app/controllers/script_versions_controller.rb:74:in `record_view_action'
app/controllers/script_versions_controller.rb:13:in `show'

The line that is causing the error is this:

ScriptVersionViewAction.create({:target => @version, :project => @project})

ScriptVersionViewAction inherits from Action and Action has this line:

  belongs_to :target, :polymorphic => true, :with_deleted => (Object.const_defined?(:DISABLE_ACTS_AS_PARANOID) ? false : true)

'desert' is a problematic plugin that is supposed to make it "easy" to customize other plugins, it might be part of the problem, but I don't think it's the root cause. 'aws-s3' is a gem for dealing with Amazon's S3 service. It's quite invasive making changes Kernel, Object, and Module. In this case it's overriding Module#const_missing to it's own version. Despite all this, it used to work before I made my change.

I have had a similar issue with the S3 gem before, and I was able to just require the file it thought was missing in the file that was having the issue, but in this case there's no file to require, it's just interpreting it wrong.