Skip to content

Instantly share code, notes, and snippets.

@slaith
Created September 3, 2013 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slaith/6425027 to your computer and use it in GitHub Desktop.
Save slaith/6425027 to your computer and use it in GitHub Desktop.
item.rb error
class Item < ActiveRecord::Base
attr_accessible :name, :price, :priority,:picture,:url
belongs_to :user
validates :name, presence: true
validates :price, presence: true
validates :price, length: { :maximum => 7}
has_attached_file :picture,:styles => {:small => "100x100>"}
validates_attachment_size :picture, :less_than => 5.megabytes
validates :url, format: /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix
validates_attachment_content_type :picture, :content_type => ['image/jpeg', 'image/png']
validates :price,:numericality => true, :allow_nil => true
#default_scope {where "completed<>trued"}
def source
hostname=@url.split('/')[2]//This doesn't work: nilClass for url
hostname=self.url.split('/')[2]//This does
hostname["www."]=""
hostname.capitalize
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment