2 class License < ActiveRecord::Base
3 belongs_to :license_group
4 belongs_to :system_picture
6 validates :license_group_id, :presence => true, :numericality => true, :existence => true
7 validates :name, :presence => true, :length => {:maximum => 50}
8 validates :caption, :presence => true, :length => {:maximum => 30}
9 validates :url, :presence => true, :length => {:maximum => 200}, :uniqueness => true, :url => true #{:allow_blank => true}
10 validates :system_picture_id, :presence => true, :numericality => true, :existence => true
12 def self.store name, attr
13 r = License.replace_system_picture attr
14 l = License.modify_object name, attr
16 l.errors.add :base, 'system picture can not create'
25 return 0 unless attrs.is_a?(Hash)
26 attrs.each do |name, attr|
27 l = License.store name, attr
28 res += 1 unless l.valid?
33 def self.list lg_id, opt = {}
34 opt.merge!(self.list_opt) unless opt[:include]
35 opt.merge!({:conditions => ['licenses.license_group_id = ?', lg_id], :order => 'name'})
36 License.find(:all, opt)
40 {:include => {:license_group => {}}}
43 def self.list_json_opt
44 {:include => {:license_group => {}}}
47 def self.show rid, opt = {}
48 r = License.find(rid, :include => self.show_include_opt(opt))
49 # raise ActiveRecord::Forbidden unless c.visible?(au)
53 def self.show_include_opt opt = {}
54 res = [:license_group]
55 res.push(opt[:include]) if opt[:include]
59 def self.show_json_include_opt
60 {:include => {:license_group => {}}}