0

I have an array of objects returned from Rest in JSON format, when I debug I just see the reference. I have added the do loop to one of my views, but I don't have any properties of the object. Is there something I need to do like cast the array? I'm new to ruby and have searched and found nothing specific to this.

First controller not PolicyList

   data3 = data2.map { |rd| PolicyList.new(rd["policyNbr"], rd["systemId"], rd["insuredName"], rd["type"], rd["statusCd"], rd["statusDes"], rd["payorZipcode"], rd["lastPaymentDate"], rd['lastPaymentAmount'], rd["pastDueDate"], rd["pastDueAmount"], rd["currentDueDate"], rd["currentDueAmount"], rd["eft"], rd["suspenseAmt"], rd["expireTime"]) }
     $policylist =data3       
     puts data3.inspect


    WebView.navigate(url_for(:controller => :PolicyList, :action => :index))

PolicyList Controller

      def index
        #@policylists = PolicyList.find(:all)
         @policylists = $policylist
         render :back => '/app'
      end

PolicyList index.erb

  <ul data-role="listview">
  <% @policylists.each do |policylist| %>

      <li>
        <a href="<%= url_for :action => :show, :id => policylist.policyNbr %>">
          <%= policylist.policyNbr %>
        </a>
      </li>

  <% end %>
</ul>

PolicyList class

 # The model has already been created by the framework, and extends Rhom::RhomObject
 # You can add more methods here
 class PolicyList
       include Rhom::PropertyBag
         attr_accessor  :policyNbr, :systemId, :insuredName,
            :type, :statusCd, :statusDes, :payorZipcode,
            :lastPaymentDate,:lastPaymentAmount,:pastDueDate,
            :pastDueAmount,:currentDueDate,:currentDueAmount,:eft,
            :suspenseAmt,:expireTime
Justin Cox
  • 326
  • 4
  • 22

1 Answers1

0

Try inspect data2 variable (before the mapping).
Possibly the data in JSON has a root element, like this:

[
 {"policy":{
   "policyNbr":"1",
   "systemId":"2"
   }
 },
 {"policy":{
   "policyNbr":"3",
   "systemI‌​d":"4"
   }
 }
]
Douglas Lise
  • 1,466
  • 1
  • 20
  • 46
  • Thanks for responding. I checked and the json message to array is in the format [{ "policyNbr":"1","systemId":"2"}, {"policyNbr":"3","systemI‌d":"4}] data 3 = [#, #, #] – Justin Cox Mar 04 '13 at 19:26
  • OK. So this depends on how your class members are declared. Are these fields in PolicyList class declared with attr_accessible ? – Douglas Lise Mar 04 '13 at 20:34
  • That should be done as an update to the OP, so other people can see it more easily. – BlackHatSamurai Mar 05 '13 at 00:09