Skip to content

Commit

Permalink
adding sex to observations
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Davey authored and Patrick Davey committed Mar 7, 2012
1 parent cc3869a commit 4996fd1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/models/observation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Observation < ActiveRecord::Base
COORDINATE_REGEX = /[^\d\,]*?(#{FLOAT_REGEX})[^\d\,]*?/
LAT_LON_SEPARATOR_REGEX = /[\,\s]\s*/
LAT_LON_REGEX = /#{COORDINATE_REGEX}#{LAT_LON_SEPARATOR_REGEX}#{COORDINATE_REGEX}/
OBSERVATION_SEX = ["Male", "Female" ,"In Pair", "Mixed"]

PRIVATE = "private"
OBSCURED = "obscured"
Expand Down Expand Up @@ -157,6 +158,7 @@ class Observation < ActiveRecord::Base
validate :must_be_in_the_past,
:must_not_be_a_range

validates_inclusion_of :sex, :in => OBSERVATION_SEX, :message => "%{value} is not a valid sex", :allow_blank => true
validates_numericality_of :latitude,
:allow_blank => true,
:less_than_or_equal_to => 90,
Expand Down
5 changes: 4 additions & 1 deletion app/views/observations/_form_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
e.g. "<%= Date.today.to_s(:long) %>" or "<%= Date.today.to_s(:long) %> 21:22" or "yesterday"
</div>
</div>

<div class="field">
<%= o.label(:sex, 'Sex') %>
<%= o.select(:sex,Observation::OBSERVATION_SEX, {:prompt => 'Select sex'}) %>
</div>
<div class="field">
<%= o.label(:number_individuals, 'Number of individuals') %>
<%= o.text_field(:number_individuals) %>
Expand Down
6 changes: 6 additions & 0 deletions app/views/observations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@
</div>
</div><!-- end where -->
</div><!-- end where-and-photos -->
<% unless @observation.sex.blank? %>
<div class="description">
<label>Sex:</label>
<%= @observation.sex %>
</div>
<% end %>
<% unless @observation.number_individuals.blank? %>
<div class="description">
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20120307031141_add_sex_to_observation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddSexToObservation < ActiveRecord::Migration
def self.up
add_column :observations, :sex, :string
end

def self.down
remove_column :observations, :sex
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120307013130) do
ActiveRecord::Schema.define(:version => 20120307031141) do

create_table "activity_streams", :force => true do |t|
t.integer "user_id"
Expand Down Expand Up @@ -365,6 +365,7 @@
t.string "license"
t.point "geom", :limit => nil
t.integer "number_individuals"
t.string "sex"
end

add_index "observations", ["geom"], :name => "index_observations_on_geom", :spatial => true
Expand Down

0 comments on commit 4996fd1

Please sign in to comment.