One flaw of Rails

… is that it’s only relatively recently become popular so it can be hard finding advice on problems when programming. I’ve come across a couple of issues so far where I’ve posted on forums and it’s taken a day or two before you get any kind of response and a couple of times there just plain hasn’t been a response.

I think Ruby developers seem to gravitate more towards mailing lists however, so I may have to try using one of them instead.

I’m currently having trouble with the following issue. If you know of a solution, PLEASE let me know. Otherwise, if I ever find a solution I’ll try to post here for others’ reference.

  • Dynamic class names
    • I’ve found the answer to the first part of this (i.e. being able to instantiate a class where the class name is variable), you use:
      • foo = object.const_get(”class_name”).new
    • The second part is a problem caused by Rails controller ‘modules’ - i.e. where you have SomeName::SomeController which isn’t a constant. I thought I’d found the answer when I found this mention on Ruby Weekly News of a method class_name.constantize but I now get this error:
      • Manage::UsersController is not a symbol
    • Full description of the problem with code

4 Responses to “One flaw of Rails”

  1. scott Says:

    Perhaps this will help you:

    http://redcorundum.blogspot.com/2006/05/kernelqualifiedconstget.html

  2. Ken Says:

    Hmmm, this sounds like a challenge. I had quick thought just from my understanding how the constants work. The reason might be because that class is in a module you need to let it know what module it belongs to so in your case:

    c = Object.const_get(ctrl).new

    may need to be, say ctrl is in AdamsModule:

    c = AdamsModule.const_get(ctrl).new

    rather than Object, but off course the snag is you need to know its module, but also it may be an issue if your modules have parent modules, erk!

    I may have some time later in the weekend to help you work this out, this is a stab in the dark for now. Let me know how you get on.

  3. supersonic feet » An evening’s work Blog Archive Says:

    […] Contact « One flaw of Rails […]

  4. Adam Says:

    Thanks both of you - will have another go at it either later tonight or tomorrow, bit knackered at the moment thanks to this :)

Leave a Reply