move swag fields to partial
This commit is contained in:
parent
93f7e07ebe
commit
e55509183c
5 changed files with 21 additions and 23 deletions
|
|
@ -61,14 +61,7 @@ module Admin
|
||||||
swags_hash = @sponsor.swags_hash
|
swags_hash = @sponsor.swags_hash
|
||||||
end
|
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
|
def get_swag_hash; end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,20 @@ class Sponsor < ActiveRecord::Base
|
||||||
belongs_to :conference
|
belongs_to :conference
|
||||||
|
|
||||||
serialize :swag_hash, Hash
|
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 }
|
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
|
||||||
|
|
||||||
mount_uploader :picture, PictureUploader, mount_on: :logo_file_name
|
mount_uploader :picture, PictureUploader, mount_on: :logo_file_name
|
||||||
|
|
||||||
validates :name, :website_url, :sponsorship_level, presence: true
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,12 @@
|
||||||
off_color: 'warning',
|
off_color: 'warning',
|
||||||
on_text: 'Yes',
|
on_text: 'Yes',
|
||||||
off_text: 'No' }
|
off_text: 'No' }
|
||||||
- @sponsor.swag_hash.each do |type, quantity|
|
|
||||||
.row
|
- @sponsor.swag_hash.each_with_index do |k, v, index|
|
||||||
.col-md-6
|
=render partial: 'swag_fields', locals: {f: f, index: index}
|
||||||
= 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
|
|
||||||
.row
|
.row
|
||||||
.col-md-8
|
.col-md-8
|
||||||
= image_tag f.object.picture.thumb.url if f.object.picture?
|
= image_tag f.object.picture.thumb.url if f.object.picture?
|
||||||
|
|
|
||||||
5
app/views/admin/sponsors/_swag_fields.html.haml
Normal file
5
app/views/admin/sponsors/_swag_fields.html.haml
Normal file
|
|
@ -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]"
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
<div class="swag_fields">
|
|
||||||
<%= f.inputs do %>
|
|
||||||
<%= f.input :type, label: 'Swags type' %>
|
|
||||||
<%= f.input :quantity, label: 'Swags quantity', as: :number, in: 0..9999 %>
|
|
||||||
<%- generate_swags_hash(@type, @quantity) %>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue