Browse Source

Fixed conference creation

development
Godwin 8 years ago
parent
commit
acecac312f
  1. 38
      app/models/conference.rb
  2. 6
      app/views/admin/new.html.haml

38
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 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 def to_param
slug slug
@ -97,6 +97,18 @@ class Conference < ActiveRecord::Base
) )
end 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 def city_name
return city.city if city.present? return city.city if city.present?
return location.present? ? location.city : nil return location.present? ? location.city : nil
@ -117,20 +129,24 @@ class Conference < ActiveRecord::Base
def self.conference_types def self.conference_types
{ {
annual: '%{city}%{year}', annual: { slug: '%{city}%{year}', title: 'Bike!Bike! %{year}'},
n: 'North%{year}', n: { slug: 'North%{year}', title: 'Bike!Bike! North %{year}'},
s: 'South%{year}', s: { slug: 'South%{year}', title: 'Bike!Bike! South %{year}'},
e: 'East%{year}', e: { slug: 'East%{year}', title: 'Bike!Bike! East %{year}'},
w: 'West%{year}', w: { slug: 'West%{year}', title: 'Bike!Bike! West %{year}'},
ne: 'Northeast%{year}', ne: { slug: 'Northeast%{year}', title: 'Bike!Bike! Northeast %{year}'},
nw: 'Northwest%{year}', nw: { slug: 'Northwest%{year}', title: 'Bike!Bike! Northwest %{year}'},
se: 'Southeast%{year}', se: { slug: 'Southeast%{year}', title: 'Bike!Bike! Southeast %{year}'},
sw: 'Southwest%{year}' sw: { slug: 'Southwest%{year}', title: 'Bike!Bike! Southwest %{year}'}
} }
end end
def self.generate_slug(type, year, city) 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
end end

6
app/views/admin/new.html.haml

@ -12,11 +12,11 @@
= textfield :city, location(@this_conference.city), required: true, big: true = textfield :city, location(@this_conference.city), required: true, big: true
= columns(medium: 12, class: 'flex-column') do = 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 = 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 = 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 = 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 = columns(medium: 12) do
.actions.next-prev .actions.next-prev
= button_tag :save, value: :save = button_tag :save, value: :save

Loading…
Cancel
Save