Created
September 16, 2016 15:03
-
-
Save over/7e52d630332e4bfca4a40d5b6d06428d to your computer and use it in GitHub Desktop.
activeadmin example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/admin/company.rb | |
ActiveAdmin.register Company do | |
config.batch_actions = false | |
menu priority: 2 | |
permit_params :name, :logo, :default_coupon_image, :stores_attributes => [:sector_id, :name] | |
actions :all, except: [:destroy] | |
index do | |
id_column | |
column :name | |
column 'Stores' do |r| | |
r.stores.count | |
end | |
column 'Coupon' do |r| | |
link_to 'New coupon', new_admin_coupon_path(company_id: r) | |
end | |
actions | |
end | |
form do |f| | |
f.inputs do | |
f.input :name | |
f.input :logo, hint: "Suggested size 690x690px" | |
f.input :default_coupon_image, hint: "This image will be displayed in the coupon if the coupon doesn't have an image. Suggested size 1020x690px" | |
end | |
f.actions | |
end | |
show do |company| | |
attributes_table do | |
row :id | |
row :name | |
row :logo do | |
image_tag(company.logo.thumb) | |
end | |
row :default_coupon_image do | |
image_tag(company.default_coupon_image.banner) | |
end | |
row :stores do | |
company.stores.map{ |store| link_to(store.name, admin_store_path(store)) }.join("<br>").html_safe | |
end | |
row :coupons do | |
company.coupons.uniq.map{ |coupon| link_to(coupon.title, admin_coupon_path(coupon)) }.join("<br>").html_safe | |
end | |
end | |
end | |
filter :name, filters: ['contains'] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment