decidim-meetings/app/commands/decidim/meetings/admin/update_meeting.rb in decidim-0.0.2 vs decidim-meetings/app/commands/decidim/meetings/admin/update_meeting.rb in decidim-0.0.3
- old
+ new
@@ -18,28 +18,40 @@
#
# Broadcasts :ok if successful, :invalid otherwise.
def call
return broadcast(:invalid) if @form.invalid?
+ change_meeting
+ return broadcast(:invalid) if Decidim.geocoder.present? && @meeting.address_changed? && !geocode_meeting
update_meeting
+
broadcast(:ok)
end
private
- def update_meeting
- @meeting.update_attributes!(
+ def change_meeting
+ @meeting.assign_attributes(
scope: @form.scope,
category: @form.category,
title: @form.title,
- short_description: @form.short_description,
description: @form.description,
end_time: @form.end_time,
start_time: @form.start_time,
address: @form.address,
location: @form.location,
location_hints: @form.location_hints
)
+ end
+
+ def geocode_meeting
+ result = @meeting.geocode
+ @form.errors.add :address, :invalid unless result
+ result
+ end
+
+ def update_meeting
+ @meeting.save!
end
end
end
end
end