Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Researching this further, I have found that <code>self.site</code> is not actually changing when I ask it to. It tells me it is changing in the logs, but it lies! <code>self.site</code> does not change from its initial set state in the first method called. I have a theory as to why this is not working and a workaround to get it working. </p> <p><strong>First, my theory:</strong></p> <p>When any one of the class methods defined is called, <code>site</code> is set. Since <code>site</code> is outside of the scope of the class method being called, once it is set initially, it cannot be changed thereafter.</p> <p>An example:</p> <pre><code>Invoice.get_details </code></pre> <p><code>Invoice.site</code> is initially set to "localhost:8080/Invoice/getDetails" </p> <pre><code>Invoice.get_pending_notifications </code></pre> <p><code>Invoice.site</code> cannot be changed because it is already defined as "localhost:8080/Invoice/getDetails"</p> <p>The above is just a working theory.</p> <p><strong>How I got this working:</strong></p> <p>Remove all references to <code>self.site</code> except for the initial set <code>self.site = "localhost:8080"</code> and instead use a url string. (Under the section "Finding resources from custom paths" at <a href="http://ofps.oreilly.com/titles/9780596521424/activeresource_id59243.html" rel="nofollow">http://ofps.oreilly.com/titles/9780596521424/activeresource_id59243.html</a> )</p> <pre><code>class Invoice &lt; ActiveResource::Base self.site = "localhost:8080" def self.define(method) define_singleton_method(method) do |params = {}| url = "#{self.site}/Invoice/#{method.to_s.camelize(:lower)}" # results = Invoice.all(params: params) &lt;- Change this call to below results = Invoice.find(:all, from: url, params: params) return results end end define :get_details define :put_approval define :get_attachment define :get_pending_notifications end </code></pre> <p>Using the code above, I can call any of the methods defined, each pointing to a different url, without issue. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload