aboutsummaryrefslogtreecommitdiff
path: root/app/models/resource.rb
diff options
context:
space:
mode:
authorIN COMMON Collective <collective@incommon.cc>2021-04-08 16:34:15 +0200
committerIN COMMON Collective <collective@incommon.cc>2021-04-08 16:34:15 +0200
commitd14700c51d692335f001a93c2f6b13b135783206 (patch)
tree1204bc1ae744098eba6604a961765187984a90d8 /app/models/resource.rb
parentc738e96b2b99bfd92b70d4cec26d6874a7f609e4 (diff)
downloadincommon-map-d14700c51d692335f001a93c2f6b13b135783206.tar.gz
[FIX] Use form model to create/edit resources (fixes #4, fixes #5, refs #3)v0.1.10
Since we must associate other models (e.g., classifications) to a Resource, we use a composite model to save all changes inside a database transaction. This approach makes it simpler to handle resources and their associations. Work remains to fix the geolocation and reverse geolocation to ensure these are in sync.
Diffstat (limited to 'app/models/resource.rb')
-rw-r--r--app/models/resource.rb11
1 files changed, 6 insertions, 5 deletions
diff --git a/app/models/resource.rb b/app/models/resource.rb
index c603978..b803afb 100644
--- a/app/models/resource.rb
+++ b/app/models/resource.rb
@@ -21,7 +21,7 @@ class Resource < ApplicationRecord
length: { in: 3..64 }
validates :email,
- with: { format: URI::MailTo::EMAIL_REGEXP },
+ format: { with: URI::MailTo::EMAIL_REGEXP },
allow_blank: true
validates :source,
@@ -31,7 +31,8 @@ class Resource < ApplicationRecord
phony_normalize :phone_number, default_country_code: 'BE', normalize_when_valid: true
validates :phone_number,
- phony_plausible: { ignore_record_country_code: true, ignore_record_country_number: true }
+ phony_plausible: { ignore_record_country_code: true, ignore_record_country_number: true },
+ allow_blank: true
# Depends on validate_url Gem
validates :website,
@@ -47,19 +48,19 @@ class Resource < ApplicationRecord
format('%<lon>3.7f', lon: feature['geometry']['coordinates'][0]).to_f
end
def longitude=(value)
- feature['geometry']['coordinates'][0] = format('%<lon>3.7f', lon: value).to_f
+ feature['geometry']['coordinates'][0] = format('%<lon>3.7f', lon: value.to_f).to_f
end
# You can use, e.g.: res.latitude = 0.123
def latitude
format('%<lat>2.7f', lat: feature['geometry']['coordinates'][1]).to_f
end
def latitude=(value)
- feature['geometry']['coordinates'][1] = format('%<lat>2.7f', lat: value).to_f
+ feature['geometry']['coordinates'][1] = format('%<lat>2.7f', lat: value.to_f).to_f
end
# Properties
- [:name, :summary, :description, :email, :source, :address, :postal_code, :city, :phone_number, :website].each do |prop|
+ [:name, :summary, :description, :email, :source, :address, :postal_code, :city, :phone_number, :website, :entry_number].each do |prop|
# Define a reader
define_method prop do
properties[prop.to_s]