Class: Picture
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Picture
- Defined in:
- app/models/picture.rb
Class Method Summary collapse
-
.create_picture_by_import(import) ⇒ Object
A picture model is create by an import model In this import model, the Gallery_id and path is usefull All information enough.
Instance Method Summary collapse
-
#define_permalink ⇒ Object
Define the permalink.
-
#ensure_permalink_is_not_a_route(permalink_test) ⇒ Object
Check if the permalink is possible for the URL /galleries/#permalink a permalinks static variable is use for performance, because the collect of routing is longer It the permalink is a route return true.
- #next ⇒ Object
-
#old_tag ⇒ Object
Return old tag save if there are difference with the tag_list work after save too.
- #previous ⇒ Object
- #to_param ⇒ Object
- #update_thumb ⇒ Object
- #update_view ⇒ Object
Class Method Details
.create_picture_by_import(import) ⇒ Object
A picture model is create by an import model In this import model, the Gallery_id and path is usefull All information enough.
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/picture.rb', line 50 def self.create_picture_by_import(import) pic = Picture.new filename = import.path.gsub(File.dirname(import.path), '') pic.title = filename[1,(filename.rindex(/\./)-1)] pic.description = '' pic.status = true pic.content_type = File.mime_type? import.path pic.filename = import.path pic.temp_data = File.new(import.path).read pic.gallery_id = import.gallery.id pic.save! pic end |
Instance Method Details
#define_permalink ⇒ Object
Define the permalink. Test if this permalink is already use. if it already use add a -#index after
31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/picture.rb', line 31 def define_permalink self.permalink = title.downcase.gsub(/[^a-z0-9]+/i, '-') permalink_insert = self.permalink i = 1 while !Picture.find_by_permalink(permalink_insert).nil? || ensure_permalink_is_not_a_route(permalink_insert) do permalink_insert = "#{self.permalink}-#{i}" i = i + 1 end self.permalink = permalink_insert end |
#ensure_permalink_is_not_a_route(permalink_test) ⇒ Object
Check if the permalink is possible for the URL /galleries/#permalink a permalinks static variable is use for performance, because the collect of routing is longer It the permalink is a route return true
68 69 70 71 72 73 |
# File 'app/models/picture.rb', line 68 def ensure_permalink_is_not_a_route(permalink_test) @@permalinks ||= ActionController::Routing::Routes.routes.collect {|r| r.generation_structure.match(/"\/pictures\/([\w]+)/)[1] rescue nil }.uniq.compact @@permalinks.include?(permalink_test) end |
#next ⇒ Object
100 101 102 103 |
# File 'app/models/picture.rb', line 100 def next Picture.find(:first, :conditions => ['gallery_id = ? AND created_at >= ? AND id > ?', gallery.id, created_at, id], :order => 'created_at ASC, id ASC') end |
#old_tag ⇒ Object
Return old tag save if there are difference with the tag_list work after save too
78 79 80 81 |
# File 'app/models/picture.rb', line 78 def old_tag return [] unless @tag_list .reject { |tag| @tag_list.include?(tag.name) } end |
#previous ⇒ Object
95 96 97 98 |
# File 'app/models/picture.rb', line 95 def previous Picture.find(:first, :conditions => ['gallery_id = ? AND created_at <= ? AND id < ?', gallery.id, created_at, id], :order => 'created_at DESC, id DESC') end |
#to_param ⇒ Object
42 43 44 |
# File 'app/models/picture.rb', line 42 def to_param permalink end |
#update_thumb ⇒ Object
83 84 85 86 87 |
# File 'app/models/picture.rb', line 83 def update_thumb tmp = self.create_temp_file self.create_or_update_thumbnail(tmp, 'thumb', self.[:thumbnails][:thumb]) tmp.delete end |
#update_view ⇒ Object
89 90 91 92 93 |
# File 'app/models/picture.rb', line 89 def update_view tmp = self.create_temp_file self.create_or_update_thumbnail(tmp, 'view', self.[:thumbnails][:view]) tmp.delete end |