From 36097f6b8b0a29ec1ffcf99b30f7c0f2677cc508 Mon Sep 17 00:00:00 2001 From: alterpub Date: Sun, 31 Aug 2014 00:28:28 +0400 Subject: [PATCH] fixed https://github.com/openSUSE/osem/issues/430 --- app/controllers/admin/commercials_controller.rb | 4 ++++ app/models/commercial.rb | 6 +++++- app/views/admin/commercials/_form.html.haml | 3 ++- app/views/admin/commercials/new.html.haml | 3 ++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/commercials_controller.rb b/app/controllers/admin/commercials_controller.rb index 2a41b2dc..47bb807f 100644 --- a/app/controllers/admin/commercials_controller.rb +++ b/app/controllers/admin/commercials_controller.rb @@ -9,6 +9,10 @@ module Admin def new @commercial = @conference.commercials.build + @commercial_types = (CONFIG['commercial_types'].nil? ? [nil] : CONFIG['commercial_types'].values) + if @commercial_types.first.nil? + flash[:alert] = "You have to include 'commercial_types' in config.yml, look at config.yml.example for example" + end authorize! :create, @conference.commercials.new end diff --git a/app/models/commercial.rb b/app/models/commercial.rb index a633102c..f265d53f 100644 --- a/app/models/commercial.rb +++ b/app/models/commercial.rb @@ -5,5 +5,9 @@ class Commercial < ActiveRecord::Base validates :commercial_id, :commercial_type, presence: true - validates :commercial_type, inclusion: { in: CONFIG['commercial_types'].values }, allow_blank: true + validates :commercial_type, inclusion: { in: :get_types_enum }, allow_blank: true + + def get_types_enum + CONFIG['commercial_types'].nil? ? nil : CONFIG['commercial_types'].values + end end diff --git a/app/views/admin/commercials/_form.html.haml b/app/views/admin/commercials/_form.html.haml index ea9e75cd..91a50082 100644 --- a/app/views/admin/commercials/_form.html.haml +++ b/app/views/admin/commercials/_form.html.haml @@ -1,4 +1,4 @@ -= f.input :commercial_type, as: :select, label: 'Conference Promo Media Type', class: 'form-control', collection: CONFIG['commercial_types'].values, include_blank: false, hint: 'This media-item will be used to represent this conference at various places in OSEM.' += f.input :commercial_type, as: :select, label: 'Conference Promo Media Type', class: 'form-control', collection: @commercial_types, include_blank: false, hint: 'This media-item will be used to represent this conference at various places in OSEM.' = f.input :commercial_id, label: 'Conference Promo Media ID', as: :string %p{ class: 'help-block media-type', id: 'youtube-help' } Go to your YouTube video, click on "share" and copy everything behind http://youtu.be/" %p{ class: 'help-block media-type', id: 'slideshare-help', style: 'display:none' } Go to your SlideShare, click on "share" -> "embed" and copy the id @@ -7,3 +7,4 @@ %p{ class: 'help-block media-type', id: 'speakerdeck-help', style: 'display:none' } Go to your SpeakerDeck, click on "share" -> "embed" and copy the data-id %p{ class: 'help-block media-type', id: 'instagram-help', style: 'display:none' } Go to your Instagram photo page and copy everything behind instagram.com/p/ (without trailing /# hash symbol) = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } + diff --git a/app/views/admin/commercials/new.html.haml b/app/views/admin/commercials/new.html.haml index 875624b6..7df7b426 100644 --- a/app/views/admin/commercials/new.html.haml +++ b/app/views/admin/commercials/new.html.haml @@ -2,6 +2,7 @@ .row .col-md-8 = semantic_form_for @commercial, url: admin_conference_commercials_path(conference_id: @conference.short_title) do |f| - = render 'form', f: f + - if @commercial_types.first + = render 'form', f: f = link_to 'Back', admin_conference_commercials_path