Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Harmlessly make ActiveResource more MongoMapper friendly

#4086

We're using MongoMapper with ActiveResource. Some of our model attributes begin with an underscore and also have a value that is an array (eg - "'_child' => ['bill', 'sam', 'joe']").

The typical behavior or ActiveResource is to infer a class name from the key when the value is an array. In the example above, the default is to assume that each element of the array is a member of a class called "_child". However, this will raise an exception because constants (like class names) cannot begin with an underscore. Luckily, if the actual elements of the array are simple strings or numbers, than they will be loaded as a simple array (which is what we want).

However, ActiveResource is still a bit too eager in trying to resolve the class name. If it were to simply wait to try to instantiate the inferred class until it was really needed, then everything would work fine. So, in this patch, we simply defer the constantization until it is really needed, if at all.

This simple fix makes everything work.

Reported by Steve Shreeve · March 2nd, 2010 @ 04:35 AM

State: stale
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. José Valim
    José Valim

    Can you please include a test case in the patch please?

    March 3rd, 2010 @ 08:37 AM

  2. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • State changed from new to incomplete
    • Milestone cleared.

    March 28th, 2010 @ 09:55 PM

  3. DHH
    DHH
    • Milestone cleared.

    May 4th, 2010 @ 05:30 PM

  4. Santiago Pastorino
    Santiago Pastorino
    • State changed from incomplete to open
    • Importance changed from to Low

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:42 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:42 PM