Skip to content
Browse files

Ensure that the url for a petition image is stripped of whitespace be…

…fore saving.

(Leading whitespace causes an exception.)
  • Loading branch information...
1 parent 363dc25 commit 89001265f46af61e30630fbfcbdc5ee9cb3c3b42 Mark Steckel committed Oct 8, 2013
Showing with 10 additions and 0 deletions.
  1. +10 −0 app/models/petition_image.rb
View
10 app/models/petition_image.rb
@@ -3,6 +3,16 @@ class PetitionImage < ActiveRecord::Base
attr_accessible :url, :as => :admin
belongs_to :petition
+ before_validation :strip_whitespace
+
+ private
+
+ def strip_whitespace
+ self.url.strip! unless self.url.nil?
+ end
+
+ public
+
def s3_object_key
hash = Digest::MD5.hexdigest("#{url}")
extension = url.split('.').last

0 comments on commit 8900126

Please sign in to comment.
Something went wrong with that request. Please try again.