Skip to content

Instantly share code, notes, and snippets.

@c80609a
Last active August 29, 2015 14:20
Show Gist options
  • Save c80609a/e64ff4f3dcc7ee8a2b86 to your computer and use it in GitHub Desktop.
Save c80609a/e64ff4f3dcc7ee8a2b86 to your computer and use it in GitHub Desktop.
activeAdmin, carrierwave, has_many files, reject_if attributes NOT present, allow_destroy
ActiveAdmin.register Suit do
menu :parent => "Мебель",
:label => "Комплекты"
permit_params :title,
:color,
:material,
:material_front,
:price,
:desc,
:suit_photos_attributes => [:id,:image,:_destroy],
:item_ids => [],
:complect_ids => [],
:special_prop_ids => []
index do
id_column
column :title do |suit|
"<div class='suit_title_in_table'>#{suit.title}</div>".html_safe
end
column :price
column :items do |suit|
lis = ((suit.items.map { |i|
"<li>#{ image_tag i.image(:thumb) }</li>"
}).join("")).html_safe
"<ul class='suit_items_tn_table'>#{lis}</ul>".html_safe
end
column :special_props do |suit|
admh_render_special_props_list(suit)
end
actions
end
form(:html => {:multipart => true}) do |f|
f.inputs "Новый комплект" do
f.input :title
f.inputs "Фотографии комплекта" do
f.has_many :suit_photos, :allow_destroy => true do |sph|
# if sph.object.new_record?
sph.input :image,
:as => :file,
:hint => sph.template.image_tag(sph.object.image)
# else
# sph.template.image_tag(sph.object.image)
# end
end
end
f.input :complects,
:as => :select,
:input_html => {
:class => "suit_collection_selector",
:size => 1,
:multiple => false
},
collection: Complect.all
f.input :color
f.input :material
f.input :material_front
f.input :desc, :as => :ckeditor
f.input :items,
:as => :check_boxes,
:label => "",
:multiple => true,
:collection => Item.where(:category_id => 2),
:wrapper_html => {:class => 'suit_item_selector', :id => "sis_first"},
:member_label => Proc.new { |it|
"<img src='#{it.image(:thumb)}'/><br/>#{it.name}".html_safe
}
f.input :items,
:label => "",
:as => :check_boxes,
:multiple => true,
:collection => Item.where(:category_id => 1),
:wrapper_html => {:class => 'suit_item_selector'},
:member_label => Proc.new { |it|
"<img src='#{it.image(:thumb)}'/><br/>#{it.name}".html_safe
}
f.input :items,
:label => "",
:as => :check_boxes,
:multiple => true,
:collection => Item.where(:category_id => 6),
:wrapper_html => {:class => 'suit_item_selector'},
:member_label => Proc.new { |it|
"<img src='#{it.image(:thumb)}'/><br/>#{it.name}".html_safe
}
f.input :price
f.input :special_props, :as => :check_boxes,
:multiple => true,
:member_label => Proc.new { |sp|
"<img src='#{asset_path(sp.icon)}'/> #{sp.desc}".html_safe
}
end
f.actions
end
end
@c80609a
Copy link
Author

c80609a commented Apr 29, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment