Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. @Data = Array.new
  2. @Devices = Devices.all
  3. @Devices.each do |d|
  4. p = d.device_property
  5.  
  6. @Data.push({
  7. :device => {
  8. :id => d.id,
  9. :ip => d.ip,
  10. :mac => d.mac,
  11. :created_at => d.created_at,
  12. :updated_at => d.updated_at,
  13. :device_property_id => p.id,
  14. :property_name => p.property_name,
  15. :cli_enabled => p.cli_enabled
  16. }
  17. })
  18. end
  19.  
  20. render json: {
  21. "status" => "success",
  22. "data" => @Data
  23. }
  24.  
  25. @Data = Device.select("devices.*, device_properties.*").joins(:device_property)
  26.  
  27. {
  28. "device" : {
  29. "id" : 13,
  30. "ip" : "192.168.1.2",
  31. "mac": "12:34:56:78:90:AB",
  32. "created_at" : "Oct 24th 2016",
  33. "updated_at" : "Oct 24th 2016",
  34. "device_property_id" : 13,
  35. "property_name" : "Disabled CLI",
  36. "cli_enabled" : false
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement