This project is archived and is in readonly mode.

#4481 ✓stale

ActiveResource.find :from won't fill prefix_options on loaded resources

Reported by Juan | April 26th, 2010 @ 09:54 PM

I have a problem, the ActiveResource.find method normally will fill the prefix_options on loaded resources, so the loaded resources will be able to do something with them, while refering to the correct URL.

But when I used the :from option, to be able to use a RESTFUL action on a resource, the loaded resources didn't have those prefix_options filled, so I needed to do that by hand, or by code!

class Call < ActiveResource::Base = "http://localhost:3000/accounts/:account_id/" end

calls = Call.find(:all, :params => { account_id => 1})
call = calls.first
call.state = "NEW_STATE" -> Give 200 OK
path generated will be = "http://localhost:3000/accounts/1/calls.xml"

calls = Call.find(:all, :from => :available, :params => { account_id => })
.... -> Give 404 status

path generated will be = "http://localhost:3000/accounts//calls.xml"

What I did was:

calls.each do |call|
call.prefix_options[:account_id => 1] end

And that worked, but I don't think that diference in behavior is fine when find is used with :from.

Thanks in advance,

Comments and changes to this ticket

  • Ryan Bigg

    Ryan Bigg April 27th, 2010 @ 12:46 AM

    • State changed from “new” to “incomplete”

    Please create a failing test case for this issue.

  • Juan

    Juan April 27th, 2010 @ 09:34 PM

    I think I found another incorrect behavior, when an AR item returned from find or find :form gets saved it looses it's prefix_options, so if you save it, and after that you want to do anything with that object the url will be malformed.

    Both behaviors are in the test case attached.

  • Juan

    Juan May 17th, 2010 @ 05:30 AM

    • Assigned user set to “Ryan Bigg”
  • Neeraj Singh

    Neeraj Singh May 18th, 2010 @ 03:08 AM

    Hi Juan,

    I'm sorry but I'm unable to follow you.

    As per you

    Call.find(:all, :params => { account_id => 1})

    is generating



    Call.find(:all, :from => :available, :params => { account_id => })

    is generating


    So what's the issue here?

  • Juan

    Juan May 18th, 2010 @ 09:16 PM

    The generated url for the resources = Call.find :all is OK in both calls.

    The problem is when using :from => :method the returned resources when you do will produce that incomplete and invalid url.

    Looking at the activeresource source I found that in some cases, including the :from method the resources loaded looses the prefix_options.

    This is ok:
    resources = Call.find(:all, :params => { :account_id => 1})
    resources[0].save => produced a valid URL

    This is not ok:
    resources = Call.find(:all, :from => :method, :params => { :account_id => 1})
    resources[0].save => produced an invalid URL -> returned resource looses the prefix_options[:account_id] that could make up the correct URL.

    I hope I could clarify a little the I think incorrect behavior.


  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:38 PM

    • State changed from “incomplete” to “open”
    • Tag changed from :from, activeresource to activeresource, from
    • 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.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:38 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket