diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index 080b0b99..e3431baf 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -61,14 +61,7 @@ module Admin swags_hash = @sponsor.swags_hash end - def generate_swags_hash(type, quantity) - unless @sponsor.swag_hash - @sponsor.swag_hash = {} - end - @sponsor.swag_hash[type.to_s] = quantity.to_i - @sponsor.update_attribute(:swag_hash, @sponsor.swag_hash) - end def get_swag_hash; end diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index 133d8dd2..e4be27f0 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -3,11 +3,20 @@ class Sponsor < ActiveRecord::Base belongs_to :conference serialize :swag_hash, Hash - attr_accessor :type, :quantity, :swag_index + attr_accessor :type, :quantity, :swag_index, :hint_hash has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id } mount_uploader :picture, PictureUploader, mount_on: :logo_file_name validates :name, :website_url, :sponsorship_level, presence: true + + def generate_swags_hash(type, quantity) + unless swag_hash + swag_hash = {} + end + + swag_hash[type.to_s] = quantity.to_i + update_attribute(:swag_hash, @sponsor.swag_hash) + end end diff --git a/app/views/admin/sponsors/_edit_form.html.haml b/app/views/admin/sponsors/_edit_form.html.haml index 9ceb326f..0855aefa 100644 --- a/app/views/admin/sponsors/_edit_form.html.haml +++ b/app/views/admin/sponsors/_edit_form.html.haml @@ -22,14 +22,12 @@ off_color: 'warning', on_text: 'Yes', off_text: 'No' } - - @sponsor.swag_hash.each do |type, quantity| - .row - .col-md-6 - = f.input :type, label: 'Swag type' - .col-md-6 - = f.input :quantity, as: :number, in: 0..9999 - - generate_swags_hash(@type, @quantity) - = f.submit 'Add Swag', :type + + - @sponsor.swag_hash.each_with_index do |k, v, index| + =render partial: 'swag_fields', locals: {f: f, index: index} + + + .row .col-md-8 = image_tag f.object.picture.thumb.url if f.object.picture? diff --git a/app/views/admin/sponsors/_swag_fields.html.haml b/app/views/admin/sponsors/_swag_fields.html.haml new file mode 100644 index 00000000..98eeb9af --- /dev/null +++ b/app/views/admin/sponsors/_swag_fields.html.haml @@ -0,0 +1,5 @@ +.row + .col-md-6 + = text_field_tag "sponsor[swag_hash][#{index}][type]" + .col-md-6 + = text_field_tag "sponsor[swag_hash][#{index}][quantity]" diff --git a/app/views/admin/sponsors/_swags.erb b/app/views/admin/sponsors/_swags.erb deleted file mode 100644 index ef3ac6a1..00000000 --- a/app/views/admin/sponsors/_swags.erb +++ /dev/null @@ -1,7 +0,0 @@ -