mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-26 18:56:06 -04:00
37 lines
759 B
Ruby
37 lines
759 B
Ruby
class Crop < ActiveRecord::Base
|
|
extend FriendlyId
|
|
friendly_id :system_name, use: :slugged
|
|
attr_accessible :en_wikipedia_url, :system_name
|
|
has_many :scientific_names
|
|
has_many :plantings
|
|
default_scope order("lower(system_name) asc")
|
|
|
|
validates :en_wikipedia_url,
|
|
:format => {
|
|
:with => /^https?:\/\/en\.wikipedia\.org\/wiki/,
|
|
:message => 'is not a valid English Wikipedia URL'
|
|
}
|
|
|
|
def Crop.random
|
|
@crop = Crop.offset(rand(Crop.count)).first
|
|
return @crop
|
|
end
|
|
|
|
def to_s
|
|
return system_name
|
|
end
|
|
|
|
def default_scientific_name
|
|
if scientific_names.count > 0
|
|
return scientific_names.first.scientific_name
|
|
else
|
|
return nil
|
|
end
|
|
end
|
|
|
|
def plantings_count
|
|
return plantings.count
|
|
end
|
|
|
|
end
|