Class: Resource
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Resource
- Defined in:
- vendor/plugins/resources/app/models/resource.rb
Constant Summary collapse
- MAX_SIZE_IN_MB =
What is the max resource size a user can upload
50
- PAGES_PER_DIALOG =
when a dialog pops up with images, how many images per page should there be
12
- PAGES_PER_ADMIN_INDEX =
when listing images out in the admin area, how many images should show per page
20
Class Method Summary collapse
-
.per_page(dialog = false) ⇒ Object
How many images per page should be displayed?.
Instance Method Summary collapse
-
#title ⇒ Object
Returns a titleized version of the filename my_file.pdf returns My File.
-
#type_of_content ⇒ Object
used for searching.
-
#validate ⇒ Object
we could use validates_as_attachment but it produces 4 odd errors like “size is not in list”.
Class Method Details
.per_page(dialog = false) ⇒ Object
How many images per page should be displayed?
40 41 42 |
# File 'vendor/plugins/resources/app/models/resource.rb', line 40 def self.per_page(dialog = false) dialog ? PAGES_PER_DIALOG : PAGES_PER_ADMIN_INDEX end |
Instance Method Details
#title ⇒ Object
Returns a titleized version of the filename my_file.pdf returns My File
51 52 53 |
# File 'vendor/plugins/resources/app/models/resource.rb', line 51 def title CGI::unescape(self.filename).gsub(/\.\w+$/, '').titleize end |
#type_of_content ⇒ Object
used for searching
45 46 47 |
# File 'vendor/plugins/resources/app/models/resource.rb', line 45 def type_of_content self.content_type.split("/").join(" ") end |
#validate ⇒ Object
we could use validates_as_attachment but it produces 4 odd errors like “size is not in list”. So we basically here enforce the same validation rules here except display the error messages we want This is a known problem when using attachment_fu
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'vendor/plugins/resources/app/models/resource.rb', line 15 def validate if self.filename.nil? errors.add_to_base("You must choose a file to upload") else [:size].each do |attr_name| enum = [attr_name] unless enum.nil? || enum.include?(send(attr_name)) errors.add_to_base("Files should be smaller than #{MAX_SIZE_IN_MB} MB in size") if attr_name == :size end end end end |