Skip to content

Commit

Permalink
Add validations for filesize and content-type.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfiredrill committed Aug 1, 2011
1 parent c863a2c commit 40abe17
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/models/leaf.rb
Expand Up @@ -12,6 +12,8 @@ class Leaf < ActiveRecord::Base
:path => "/:style/:filename"

validate :validates_photo_or_post
validates_attachment_content_type :photo, :content_type => VALID_ATTACHMENT_TYPES
validates_attachment_size :photo, :less_than => MAX_UPLOAD_SIZE, :message => "File too big! :{"

def validates_photo_or_post
errors.add(:leaf, "must have text or a picture, why would you want to make a
Expand Down
3 changes: 2 additions & 1 deletion fortconfig.rb
Expand Up @@ -16,7 +16,8 @@
#LEAFS_PER_BRANCH = 10 #replies per thread shown

#limitations
#MAX_UPLOAD_SIZE = 5000 #max upload size in KB for images
#MAX_UPLOAD_SIZE = 5.megabytes #max upload size in KB for images
#VALID_ATTACHMENT_TYPES = ['image/jpg', 'image/png', 'image/gif', 'image/pjpeg', 'image/tiff', 'image/x-png', 'image/bmp', 'image/svg-xml'] #valid image MIME types, all others will be rejected

#misc
#SMILEY_ASSIST = true #boolean, turns smiley assistant on or off
2 changes: 2 additions & 0 deletions fortconfig_defaults.rb
Expand Up @@ -2,3 +2,5 @@
eval "BRANCHES_PER_PAGE = 10" unless defined? BRANCHES_PER_PAGE
eval "SHOWTITLETXT=true" unless defined? SHOWTITLETXT
eval "SMILEY_ASSIST=true" unless defined? SMILEY_ASSIST
eval "MAX_UPLOAD_SIZE = 5.megabytes" unless defined? MAX_UPLOAD_SIZE
eval "VALID_ATTACHMENT_TYPES = ['image/jpg', 'image/png', 'image/gif', 'image/pjpeg', 'image/tiff', 'image/x-png', 'image/bmp', 'image/svg-xml']" unless defined? VALID_ATTACHMENT_TYPES
2 changes: 1 addition & 1 deletion script/rails
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby18
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.

APP_PATH = File.expand_path('../../config/application', __FILE__)
Expand Down

0 comments on commit 40abe17

Please sign in to comment.