Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm the creator of acts_as_api. I tried your use case with a minimal Rails app and it worked for me. Here is an example response in xml:</p> <pre><code>&lt;users type="array"&gt; &lt;user&gt; &lt;first-name&gt;Me&lt;/first-name&gt; &lt;recieved-date type="datetime"&gt;2011-10-07T08:20:02Z&lt;/recieved-date&gt; &lt;/user&gt; &lt;user&gt; &lt;first-name&gt;Me2&lt;/first-name&gt; &lt;actual-date type="datetime"&gt;2011-10-07T08:20:52Z&lt;/actual-date&gt; &lt;/user&gt; &lt;/users&gt; </code></pre> <p>The api template in the model looks like this:</p> <pre><code>api_accessible :test_dates do |t| t.add :first_name t.add :common_date, :as =&gt; :recieved_date, :if =&gt; lambda{|u|u.date_type_code=="RECVD"} t.add :common_date, :as =&gt; :actual_date, :if =&gt; lambda{|u|u.date_type_code=="ARRIV"} end </code></pre> <p>And this is a dump of User.all:</p> <pre><code>[ [0] #&lt;User:0x0000010b859308&gt; { :id =&gt; 1, :first_name =&gt; "Me", :last_name =&gt; "Too", :age =&gt; nil, :active =&gt; nil, :created_at =&gt; Fri, 07 Oct 2011 08:20:19 UTC +00:00, :updated_at =&gt; Fri, 07 Oct 2011 08:20:19 UTC +00:00, :date_type_code =&gt; "RECVD", :common_date =&gt; Fri, 07 Oct 2011 08:20:02 UTC +00:00 }, [1] #&lt;User:0x0000010b858688&gt; { :id =&gt; 2, :first_name =&gt; "Me2", :last_name =&gt; "Too2", :age =&gt; nil, :active =&gt; nil, :created_at =&gt; Fri, 07 Oct 2011 08:20:45 UTC +00:00, :updated_at =&gt; Fri, 07 Oct 2011 08:20:53 UTC +00:00, :date_type_code =&gt; "ARRIV", :common_date =&gt; Fri, 07 Oct 2011 08:20:52 UTC +00:00 } ] </code></pre> <p>Did you check that you use the controller helpers correctly?</p> <pre><code>def index @users = User.all respond_to do |format| format.html # index.html.erb format.xml { render_for_api :test_dates, :xml =&gt; @users, :root =&gt; :users } format.json { render_for_api :test_dates, :json =&gt; @users, :root =&gt; :users } end end </code></pre> <p>I hope this helps. :)</p> <p>Further debugging could include: * What happens if you remove the :if options? * What does 'puts u.date_type_code' say if you put it in the :if options blocks?</p>
 

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