Guest User

Untitled

a guest
Aug 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. rails: datetimes fields do not fetch the values
  2. acts_as_api
  3.  
  4. api_accessible :bill_corrections do |inv|
  5. inv.add :common_date, :as => :recieved_date, :if => lambda{|u|u.date_type_code=="RECVD"}
  6. inv.add :common_date, :as => :actual_date, :if => lambda{|u|u.date_type_code=="ARRIV"}
  7. end
  8.  
  9. create_table "item_dates", :force => true do |t|
  10. t.integer "item_date_id", :limit => 10
  11. t.string "date_type_code"
  12. t.datetime "common_date"
  13. t.datetime "created_at"
  14. t.datetime "updated_at"
  15. end
  16.  
  17. <users type="array">
  18. <user>
  19. <first-name>Me</first-name>
  20. <recieved-date type="datetime">2011-10-07T08:20:02Z</recieved-date>
  21. </user>
  22. <user>
  23. <first-name>Me2</first-name>
  24. <actual-date type="datetime">2011-10-07T08:20:52Z</actual-date>
  25. </user>
  26. </users>
  27.  
  28. api_accessible :test_dates do |t|
  29. t.add :first_name
  30. t.add :common_date, :as => :recieved_date, :if => lambda{|u|u.date_type_code=="RECVD"}
  31. t.add :common_date, :as => :actual_date, :if => lambda{|u|u.date_type_code=="ARRIV"}
  32. end
  33.  
  34. [
  35. [0] #<User:0x0000010b859308> {
  36. :id => 1,
  37. :first_name => "Me",
  38. :last_name => "Too",
  39. :age => nil,
  40. :active => nil,
  41. :created_at => Fri, 07 Oct 2011 08:20:19 UTC +00:00,
  42. :updated_at => Fri, 07 Oct 2011 08:20:19 UTC +00:00,
  43. :date_type_code => "RECVD",
  44. :common_date => Fri, 07 Oct 2011 08:20:02 UTC +00:00
  45. },
  46. [1] #<User:0x0000010b858688> {
  47. :id => 2,
  48. :first_name => "Me2",
  49. :last_name => "Too2",
  50. :age => nil,
  51. :active => nil,
  52. :created_at => Fri, 07 Oct 2011 08:20:45 UTC +00:00,
  53. :updated_at => Fri, 07 Oct 2011 08:20:53 UTC +00:00,
  54. :date_type_code => "ARRIV",
  55. :common_date => Fri, 07 Oct 2011 08:20:52 UTC +00:00
  56. }
  57. ]
  58.  
  59. def index
  60. @users = User.all
  61.  
  62. respond_to do |format|
  63. format.html # index.html.erb
  64. format.xml { render_for_api :test_dates, :xml => @users, :root => :users }
  65. format.json { render_for_api :test_dates, :json => @users, :root => :users }
  66. end
  67. end
Add Comment
Please, Sign In to add comment