Guest User

Untitled

a guest
May 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. ## device.rb
  2.  
  3. class Device < ActiveRecord::Base
  4. validates_presence_of(:name, :message => "is required")
  5. validates_presence_of(:systemtype, :message => "is required")
  6. belongs_to :picture
  7. has_many :devicemodels,:dependent => :delete_all
  8. has_many :carmodels,:through => :devicemodels
  9. belongs_to :systemtype
  10. belongs_to :devicetype
  11.  
  12. before_destroy :delete_associated_picture
  13.  
  14. def self.get_random_product
  15. devices = Device.find(:all,:conditions => ['picture_id!=?',0])
  16. devices[rand(devices.size)]
  17. end
  18.  
  19. def self.find_by_carbrand_id(id)
  20. devices = Device.find(:all)
  21. devices_array = []
  22. for device in devices
  23. for carmodel in device.carmodels
  24. print "======================"
  25. print "========test========" if carmodel.carbrand.id == id
  26. end
  27. end
  28. devices_array
  29. end
  30.  
  31.  
  32. private
  33. def delete_associated_picture
  34. picture.destroy if picture
  35. end
  36. end
  37.  
  38. ## devicemodel.rb
  39.  
  40. class Devicemodel < ActiveRecord::Base
  41. validates_presence_of(:carmodel, :message => "a carmodel is required")
  42. validates_presence_of(:device, :message => "a device is required")
  43. belongs_to :carmodel
  44. belongs_to :device
  45. end
  46.  
  47. ## carmodel.rb
  48.  
  49. class Carmodel < ActiveRecord::Base
  50.  
  51. validates_presence_of(:name, :message => "is required")
  52. validates_presence_of(:fromyear, :message => "is required")
  53. validates_presence_of(:toyear, :message => "is required")
  54. validates_presence_of(:carbrand, :message => "carbrand is required")
  55.  
  56. belongs_to :picture
  57. belongs_to :carbrand
  58. has_many :devicemodels
  59. has_many :devices , :through => :devicemodels
  60. has_many :servicemodels
  61. has_many :services , :through => :servicemodels
  62.  
  63. before_destroy :check_constraints
  64. after_destroy :delete_associated_picture
  65.  
  66.  
  67. def validate
  68. if fromyear
  69. if toyear
  70. errors.add("","From year should be earlier then To year") if fromyear>toyear
  71. else
  72. errors.add("","is required")
  73. end
  74. else
  75. errors.add("","is required")
  76. end
  77. end
  78.  
  79. def self.startyear
  80. 1985
  81. end
  82.  
  83. def self.endyear
  84. DateTime::now().strftime("%Y").to_i
  85. end
  86.  
  87. private
  88. # check to see if there are childrecords ,
  89. # if so don't allow destroy
  90. def check_constraints
  91. devicemodels.count == 0
  92. end
  93. def delete_associated_picture
  94. Picture.destroy(picture_id) if Picture.exists?(picture_id)
  95. end
  96.  
  97. end
  98.  
  99. ## stacktrace
  100.  
  101. SystemStackError in Admin/devicesController#edit
  102.  
  103. stack level too deep
  104. RAILS_ROOT: /Volumes/BACKUPS/Development/ruby/apps/motorecu
  105.  
  106. Application Trace | Framework Trace | Full Trace
  107. vendor/plugins/will_paginate/lib/will_paginate/finder.rb:93:in `method_missing_without_paginate'
  108. vendor/plugins/will_paginate/lib/will_paginate/finder.rb:93:in `method_missing'
  109. app/controllers/admin/devices_controller.rb:67:in `edit'
  110. /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1166:in `send'
  111. /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1166:in `perform_action_without_filters'
  112. /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:579:in `call_filters'
  113. /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:572:in `perform_action_without_benchmark'
  114. /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
  115. /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
  116. /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/rescue.rb:201:in `perform_action_without_caching'
  117. /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/caching/sql_cache.rb:13:in `perform_action'
  118. /Library/Ruby/Gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
  119. /Library/Ruby/Gems/1.8/gems/activerecord-2.1.1/lib/active_record/query_cache.rb:8:in `cache'
  120. /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/caching/sql_cache.rb:12:in `perform_action'
  121. /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:529:in `send'
  122. /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:529:in `process_without_filters'
  123. /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:568:in `process_without_session_management_support'
  124. /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/session_management.rb:130:in `process'
  125. /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:389:in `process'
  126. /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in `load'
  127. /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in `load'
  128. /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in `new_constants_in'
  129. /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in `load'
  130. /Library/Ruby/Gems/1.8/gems/rails-2.1.1/lib/commands/servers/mongrel.rb:64
  131. /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require'
  132. /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in `new_constants_in'
  133. /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require'
  134. /Library/Ruby/Gems/1.8/gems/rails-2.1.1/lib/commands/server.rb:39
  135. Request
  136.  
  137. Parameters:
  138.  
  139. {"id"=>"256"}
  140. Show session dump
  141.  
  142. Response
  143.  
  144. Headers:
  145.  
  146. {"cookie"=>[],
  147. "Cache-Control"=>"no-cache"}
Add Comment
Please, Sign In to add comment