namespaces problem with collections

17 visningar
Hoppa till det första olästa meddelandet

Marcel Augsburger

oläst,
30 dec. 2013 15:03:032013-12-30
till roar...@googlegroups.com
I'm having trouble with namespaces when defining a collection in a representer. I get an 'uninitialized constant' error. For instance:

Module A
  Module B
    
    collection :things, extend: ThingRepresenter, class: Thing
  end
end

throws the error 'uninitialized constant A::B::Thing'. For some reason it's looking for that class within the modules... any hints on what I could do?

Rhett Sutphin

oläst,
30 dec. 2013 15:12:232013-12-30
till roar...@googlegroups.com
Hi,

This is a ruby constant resolution behavior — if the constant can’t be resolved at any level, it will call const_missing with the most-specific possible constant name. Two possible fixes:

* Make sure that your `Thing` class is loaded before your representer. E.g., `require` the file that contains it from your representer. Or,
* Qualify the Thing constant with “::” like “::Thing”. That tells ruby to use only the Thing constant that’s defined at the top level. If there isn’t one, const_missing will be called for just “Thing” instead of “A::B::Thing”.

(I’m assuming this is in a Rails app — ActiveSupport’s autoloading behavior relies on const_missing, which is why the value that gets passed to const_missing is important.)

Rhett
> --
> You received this message because you are subscribed to the Google Groups "Roar" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to roar-talk+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Marcel Augsburger

oläst,
30 dec. 2013 15:47:472013-12-30
till roar...@googlegroups.com
Awesome! Thanks Rhett!


2013/12/30 Rhett Sutphin <rhett....@gmail.com>
Svara alla
Svara författaren
Vidarebefordra
0 nya meddelanden