From 83f1e9dbc9bca48adbb1bc7bc4c856d66d216f94 Mon Sep 17 00:00:00 2001 From: echarp Date: Sat, 22 Apr 2017 11:35:37 +0200 Subject: [PATCH] Event's url is no longer required --- app/models/event.rb | 2 +- app/views/digests/markdown.html.haml | 3 ++- app/views/events/_form.html.haml | 2 +- app/views/events/show.html.haml | 9 +++++---- app/views/events/show.text.haml | 3 ++- db/migrate/20170422083422_change_events_null_url.rb | 6 ++++++ db/schema.rb | 4 ++-- 7 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20170422083422_change_events_null_url.rb diff --git a/app/models/event.rb b/app/models/event.rb index 86a4663f..86545574 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -22,7 +22,7 @@ class Event < ActiveRecord::Base validates :description, presence: true validates :city, presence: true validates :region, presence: true - validates :url, presence: true, format: %r{\Ahttps?:\/\/.*\..*\z} + validates :url, allow_nil: true, format: %r{\Ahttps?:\/\/.*\..*\z} validates :contact, email: true validates :submitter, email: true diff --git a/app/views/digests/markdown.html.haml b/app/views/digests/markdown.html.haml index 432675fe..286b5ff3 100644 --- a/app/views/digests/markdown.html.haml +++ b/app/views/digests/markdown.html.haml @@ -22,7 +22,8 @@ = p \ * #{[event.place_name, event.full_address].compact.join ', '} - * #{Event.human_attribute_name :url}: #{link_to event.url, event.url} + - if event.url.present? + * #{Event.human_attribute_name :url}: #{link_to event.url, event.url} * #{Event.human_attribute_name :tags}: #{event.tags.collect { |tag| "[#{tag}](#{tag_url tag.name})" }.join ', '} \ diff --git a/app/views/events/_form.html.haml b/app/views/events/_form.html.haml index 15a8176a..555e0925 100644 --- a/app/views/events/_form.html.haml +++ b/app/views/events/_form.html.haml @@ -82,7 +82,7 @@ :markdown #{t '.url_helper'} = f.label :url - = f.url_field :url, required: true, placeholder: 'Ex: http://april.org' + = f.url_field :url, placeholder: 'Ex: http://april.org' .field.contact .helper :markdown diff --git a/app/views/events/show.html.haml b/app/views/events/show.html.haml index cdf84bd6..ffbb991e 100644 --- a/app/views/events/show.html.haml +++ b/app/views/events/show.html.haml @@ -97,10 +97,11 @@ %h3 %em.fa.fa-info-circle = t '.infos' -%p - %em.fa.fa-external-link - %span.label= Event.human_attribute_name :url - = link_to @event.url, @event.url +- if @event.url.present? + %p + %em.fa.fa-external-link + %span.label= Event.human_attribute_name :url + = link_to @event.url, @event.url %p %em.fa.fa-envelope %span.label= Event.human_attribute_name :contact diff --git a/app/views/events/show.text.haml b/app/views/events/show.text.haml index 3379af38..f23951fe 100644 --- a/app/views/events/show.text.haml +++ b/app/views/events/show.text.haml @@ -10,7 +10,8 @@ #{Event.human_attribute_name(:city).concat(':').ljust 12 } #{@event.city} #{Event.human_attribute_name(:region).concat(':').ljust 12 } #{@event.region} #{Event.human_attribute_name(:locality).concat(':').ljust 12 } #{t "attributes.locality_#{@event.locality}"} -#{Event.human_attribute_name(:url).concat(':').ljust 12 } #{@event.url} +- if @event.url.present? + #{Event.human_attribute_name(:url).concat(':').ljust 12 } #{@event.url} #{Event.human_attribute_name(:contact).concat(':').ljust 12 } #{@event.contact} #{Event.human_attribute_name(:submitter).concat(':').ljust 12 } #{@event.submitter} #{Event.human_attribute_name(:tags).concat(':').ljust 12 } #{@event.tag_list} diff --git a/db/migrate/20170422083422_change_events_null_url.rb b/db/migrate/20170422083422_change_events_null_url.rb new file mode 100644 index 00000000..63c6366b --- /dev/null +++ b/db/migrate/20170422083422_change_events_null_url.rb @@ -0,0 +1,6 @@ +# Event url are now optional +class ChangeEventsNullUrl < ActiveRecord::Migration + def change + change_column :events, :url, :string, default: '', null: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 928439b5..fac548fe 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161210154558) do +ActiveRecord::Schema.define(version: 20170422083422) do create_table "active_admin_comments", force: :cascade do |t| t.string "namespace", limit: 255 @@ -66,7 +66,7 @@ ActiveRecord::Schema.define(version: 20161210154558) do t.string "city", limit: 255, default: "" t.integer "region_id", limit: 4, default: 0, null: false t.integer "locality", limit: 4, default: 0, null: false - t.string "url", limit: 255, default: "", null: false + t.string "url", limit: 255, default: "" t.string "contact", limit: 255, default: "", null: false t.string "submitter", limit: 255, default: "", null: false t.integer "moderated", limit: 4, default: 0, null: false