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.

ActiveResource: prefix attributes that are mass assigned are not readable and serializable.

#6171

When I initialize a resource that uses prefixes I expect that also the attribute that is used as prefix shows up when i serialize the resource.

Failing Test:

class Foo < ActiveResource::Base
self.site = "http://example.com/bar/:bar_id/foos" end

assert_equal Foo.new(:bar_id => 1).as_json, {'foo' => {'bar_id' => 1}} #right now you will get {'foo' => {}}
assert_equal Foo.new(:bar_id => 1).bar_id, 1 # now method error.

The root of the problem is located at ActiveResoure::Base split_options Line:922 (ActiveResource 3.0.3). Maybe it is just a bad convention, and prefixes should be passed more explicitly to avoid such surprises.

Reported by Thilo Utke · December 15th, 2010 @ 02:41 PM

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

Activity

  1. rails
    rails
    • State changed from new to open

    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.

    March 16th, 2011 @ 12:00 AM

  2. rails
    rails
    • State changed from open to stale

    March 16th, 2011 @ 12:00 AM

  3. Pierre Lancien
    Pierre Lancien

    I made a patch for this issue two months ago but I forgot to submit it...
    I checked, the issue is still here in the latest Rails version. So here is my patch.

    Warning - one of the tests I added triggers the bug I previously mentioned and fixed here :
    #6195 ActiveResource : clone fails when the resource has Fixnum or boolean attributes

    (I still don't know how to apply the "patch" tag here in lighthouse, so if someone reads this, please create the tag or tell me how to do it)

    March 18th, 2011 @ 05:09 PM

  4. Matt Jones
    Matt Jones
    • State changed from stale to open
    • Importance changed from to Low

    March 18th, 2011 @ 05:25 PM

  5. Evgeniy Dolzhenko
    Evgeniy Dolzhenko

    I'm +1 on this getting merged, currently in our ActiveResource models we have to do things like

    class Foo < ActiveResource::Base
    def bar_id

    @prefix_options[:bar_id
    

    end end

    this patch would solve that (+ include the attributes in serialized version of resource)

    March 19th, 2011 @ 07:57 AM