| 
									
										
										
										
											2010-02-01 09:24:28 +00:00
										 |  |  | class Asset | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-13 10:19:51 +00:00
										 |  |  |   include Mongoid::Document | 
					
						
							| 
									
										
										
										
											2011-03-08 09:25:46 +00:00
										 |  |  |   include Mongoid::Timestamps | 
					
						
							| 
									
										
										
										
											2010-02-01 09:24:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-17 01:30:21 +00:00
										 |  |  |   mount_uploader :data, FileAssetUploader | 
					
						
							| 
									
										
										
										
											2010-02-01 09:24:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-13 10:19:51 +00:00
										 |  |  |   field :filename | 
					
						
							| 
									
										
										
										
											2012-07-25 21:07:32 +00:00
										 |  |  |   field :description, localize: true | 
					
						
							|  |  |  |   field :title, localize: true | 
					
						
							| 
									
										
										
										
											2010-02-01 09:24:28 +00:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2012-07-31 06:25:46 +00:00
										 |  |  |   validates :title, :at_least_one => true | 
					
						
							|  |  |  |   validates :description, :at_least_one => true | 
					
						
							|  |  |  |   validates_presence_of :data | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-16 03:07:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   belongs_to :asset_category | 
					
						
							|  |  |  |   belongs_to :assetable, polymorphic: true | 
					
						
							| 
									
										
										
										
											2012-05-16 22:28:29 +00:00
										 |  |  |   has_and_belongs_to_many :tags, :class_name => "AssetTag" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-14 06:38:21 +00:00
										 |  |  |   before_save :clean_tags | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-16 22:28:29 +00:00
										 |  |  |   def sorted_tags | 
					
						
							|  |  |  |     tags.order_by(I18n.locale, :asc) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-08-14 06:38:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   protected | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def clean_tags | 
					
						
							|  |  |  |     self.tag_ids.delete('') | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-02-05 08:15:16 +00:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2011-04-13 10:19:51 +00:00
										 |  |  | end |