Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## device.rb
- class Device < ActiveRecord::Base
- validates_presence_of(:name, :message => "is required")
- validates_presence_of(:systemtype, :message => "is required")
- belongs_to :picture
- has_many :devicemodels,:dependent => :delete_all
- has_many :carmodels,:through => :devicemodels
- belongs_to :systemtype
- belongs_to :devicetype
- before_destroy :delete_associated_picture
- def self.get_random_product
- devices = Device.find(:all,:conditions => ['picture_id!=?',0])
- devices[rand(devices.size)]
- end
- def self.find_by_carbrand_id(id)
- devices = Device.find(:all)
- devices_array = []
- for device in devices
- for carmodel in device.carmodels
- print "======================"
- print "========test========" if carmodel.carbrand.id == id
- end
- end
- devices_array
- end
- private
- def delete_associated_picture
- picture.destroy if picture
- end
- end
- ## devicemodel.rb
- class Devicemodel < ActiveRecord::Base
- validates_presence_of(:carmodel, :message => "a carmodel is required")
- validates_presence_of(:device, :message => "a device is required")
- belongs_to :carmodel
- belongs_to :device
- end
- ## carmodel.rb
- class Carmodel < ActiveRecord::Base
- validates_presence_of(:name, :message => "is required")
- validates_presence_of(:fromyear, :message => "is required")
- validates_presence_of(:toyear, :message => "is required")
- validates_presence_of(:carbrand, :message => "carbrand is required")
- belongs_to :picture
- belongs_to :carbrand
- has_many :devicemodels
- has_many :devices , :through => :devicemodels
- has_many :servicemodels
- has_many :services , :through => :servicemodels
- before_destroy :check_constraints
- after_destroy :delete_associated_picture
- def validate
- if fromyear
- if toyear
- errors.add("","From year should be earlier then To year") if fromyear>toyear
- else
- errors.add("","is required")
- end
- else
- errors.add("","is required")
- end
- end
- def self.startyear
- 1985
- end
- def self.endyear
- DateTime::now().strftime("%Y").to_i
- end
- private
- # check to see if there are childrecords ,
- # if so don't allow destroy
- def check_constraints
- devicemodels.count == 0
- end
- def delete_associated_picture
- Picture.destroy(picture_id) if Picture.exists?(picture_id)
- end
- end
- ## stacktrace
- SystemStackError in Admin/devicesController#edit
- stack level too deep
- RAILS_ROOT: /Volumes/BACKUPS/Development/ruby/apps/motorecu
- Application Trace | Framework Trace | Full Trace
- vendor/plugins/will_paginate/lib/will_paginate/finder.rb:93:in `method_missing_without_paginate'
- vendor/plugins/will_paginate/lib/will_paginate/finder.rb:93:in `method_missing'
- app/controllers/admin/devices_controller.rb:67:in `edit'
- /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1166:in `send'
- /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1166:in `perform_action_without_filters'
- /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:579:in `call_filters'
- /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:572:in `perform_action_without_benchmark'
- /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
- /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
- /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/rescue.rb:201:in `perform_action_without_caching'
- /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/caching/sql_cache.rb:13:in `perform_action'
- /Library/Ruby/Gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
- /Library/Ruby/Gems/1.8/gems/activerecord-2.1.1/lib/active_record/query_cache.rb:8:in `cache'
- /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/caching/sql_cache.rb:12:in `perform_action'
- /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:529:in `send'
- /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:529:in `process_without_filters'
- /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:568:in `process_without_session_management_support'
- /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/session_management.rb:130:in `process'
- /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:389:in `process'
- /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in `load'
- /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in `load'
- /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in `new_constants_in'
- /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in `load'
- /Library/Ruby/Gems/1.8/gems/rails-2.1.1/lib/commands/servers/mongrel.rb:64
- /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require'
- /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in `new_constants_in'
- /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require'
- /Library/Ruby/Gems/1.8/gems/rails-2.1.1/lib/commands/server.rb:39
- Request
- Parameters:
- {"id"=>"256"}
- Show session dump
- Response
- Headers:
- {"cookie"=>[],
- "Cache-Control"=>"no-cache"}
Add Comment
Please, Sign In to add comment