From acecac312f8c0a7cd3dd8e2eba72302a7c1503a1 Mon Sep 17 00:00:00 2001 From: Godwin Date: Sun, 25 Dec 2016 10:51:41 -0800 Subject: [PATCH] Fixed conference creation --- app/models/conference.rb | 38 +++++++++++++++++++++++++---------- app/views/admin/new.html.haml | 6 +++--- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/app/models/conference.rb b/app/models/conference.rb index 3b5195d..9744a74 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -17,7 +17,7 @@ class Conference < ActiveRecord::Base accepts_nested_attributes_for :conference_host_organizations, reject_if: proc {|u| u[:organization_id].blank?}, allow_destroy: true - before_create :make_slug + before_create :make_slug, :make_title def to_param slug @@ -97,6 +97,18 @@ class Conference < ActiveRecord::Base ) end + def make_title(reset = false) + if reset + self.title = nil + end + + self.title ||= Conference.generate_title( + conferencetype || :annual, + conference_year, + city_name.gsub(/\s/, '') + ) + end + def city_name return city.city if city.present? return location.present? ? location.city : nil @@ -117,20 +129,24 @@ class Conference < ActiveRecord::Base def self.conference_types { - annual: '%{city}%{year}', - n: 'North%{year}', - s: 'South%{year}', - e: 'East%{year}', - w: 'West%{year}', - ne: 'Northeast%{year}', - nw: 'Northwest%{year}', - se: 'Southeast%{year}', - sw: 'Southwest%{year}' + annual: { slug: '%{city}%{year}', title: 'Bike!Bike! %{year}'}, + n: { slug: 'North%{year}', title: 'Bike!Bike! North %{year}'}, + s: { slug: 'South%{year}', title: 'Bike!Bike! South %{year}'}, + e: { slug: 'East%{year}', title: 'Bike!Bike! East %{year}'}, + w: { slug: 'West%{year}', title: 'Bike!Bike! West %{year}'}, + ne: { slug: 'Northeast%{year}', title: 'Bike!Bike! Northeast %{year}'}, + nw: { slug: 'Northwest%{year}', title: 'Bike!Bike! Northwest %{year}'}, + se: { slug: 'Southeast%{year}', title: 'Bike!Bike! Southeast %{year}'}, + sw: { slug: 'Southwest%{year}', title: 'Bike!Bike! Southwest %{year}'} } end def self.generate_slug(type, year, city) - Conference.conference_types[(type || :annual).to_sym].gsub('%{city}', city).gsub('%{year}', year.to_s) + Conference.conference_types[(type || :annual).to_sym][:slug].gsub('%{city}', city).gsub('%{year}', year.to_s) + end + + def self.generate_title(type, year, city) + Conference.conference_types[(type || :annual).to_sym][:title].gsub('%{city}', city).gsub('%{year}', year.to_s) end end diff --git a/app/views/admin/new.html.haml b/app/views/admin/new.html.haml index 63cf736..633a7bb 100644 --- a/app/views/admin/new.html.haml +++ b/app/views/admin/new.html.haml @@ -12,11 +12,11 @@ = textfield :city, location(@this_conference.city), required: true, big: true = columns(medium: 12, class: 'flex-column') do = selectfield :type, @this_conference.conferencetype, Conference.conference_types.keys.map { |k| [(_"forms.options.conferences.types.#{k}"), k]}, required: true, stretch: true - = numberfield :year, @this_conference.conference_year || Date.today.year, required: true + = numberfield :year, @this_conference.conference_year || (Date.today + 6.months).year, required: true = columns(medium: 6) do - = checkbox :is_public, @this_conference.is_public != false, 'forms.labels.generic.is_public' + = checkbox :is_public, @this_conference.id.present? && @this_conference.is_public != false, 'forms.labels.generic.is_public' = columns(medium: 6) do - = checkbox :is_featured, @this_conference.is_featured != false, 'forms.labels.generic.is_featured' + = checkbox :is_featured, @this_conference.id.present? && @this_conference.is_featured != false, 'forms.labels.generic.is_featured' = columns(medium: 12) do .actions.next-prev = button_tag :save, value: :save