From dd9e0691acae3eb63bdfbc8665eb3f8ce516536d Mon Sep 17 00:00:00 2001 From: hellekin Date: Fri, 9 Oct 2020 12:47:31 +0200 Subject: Fix Resource edition --- app/models/resource.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/resource.rb b/app/models/resource.rb index 906933d..7d87e1a 100644 --- a/app/models/resource.rb +++ b/app/models/resource.rb @@ -8,8 +8,7 @@ class Resource < ApplicationRecord has_many :classifications has_many :sections, through: :classifications - serialize :feature, HashSerializer - store_accessor :feature, :name, :summary, :description, :email, :source, :address, :postal_code, :city, :phone_number, :website + store_accessor :feature, :geometry, :properties validates_associated :agent @@ -53,4 +52,16 @@ class Resource < ApplicationRecord def latitude=(value) feature['geometry']['coordinates'][1] = value end + + # Properties + + [:name, :summary, :description, :email, :source, :address, :postal_code, :city, :phone_number, :website].each do |prop| + # Define a reader + define_method prop do + properties[prop.to_s] + end + define_method :"#{prop}=" do |v| + feature['properties'][prop.to_s] = v + end + end end -- cgit v1.2.3