Class: Admin::SupplierTaxonsController
- Inherits:
-
BaseController
- Object
- BaseController
- Admin::SupplierTaxonsController
- Includes:
- Railslove::Plugins::FindByParam::SingletonMethods
- Defined in:
- app/controllers/admin/supplier_taxons_controller.rb
Instance Method Summary collapse
- #available ⇒ Object
- #batch_select ⇒ Object
- #remove ⇒ Object
- #select ⇒ Object
- #selected ⇒ Object
- #update_taxons ⇒ Object
Instance Method Details
#available ⇒ Object
14 15 16 17 18 19 |
# File 'app/controllers/admin/supplier_taxons_controller.rb', line 14 def available @supplier = load_supplier @taxons = params[:q].blank? ? [] : Taxon.where('lower(name) LIKE ?', "%#{params[:q].mb_chars.downcase}%") @taxons.delete_if { |taxon| @supplier.taxons.include?(taxon) } respond_with(:admin, @taxons) end |
#batch_select ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/controllers/admin/supplier_taxons_controller.rb', line 39 def batch_select @supplier = load_supplier @taxons = params[:taxon_ids].map{|id| Taxon.find(id)}.compact @supplier.taxons = @taxons @supplier.save redirect_to selected_admin_supplier_taxons_url(@supplier) end |
#remove ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'app/controllers/admin/supplier_taxons_controller.rb', line 21 def remove @supplier = load_supplier @taxon = Taxon.find(params[:id]) @supplier.taxons.delete(@taxon) @supplier.save @taxons = @supplier.taxons respond_with(@taxon) { |format| format.js { render_js_for_destroy } } end |
#select ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'app/controllers/admin/supplier_taxons_controller.rb', line 30 def select @supplier = load_supplier @taxon = Taxon.find(params[:id]) @supplier.taxons << @taxon @supplier.save @taxons = @supplier.taxons respond_with(:admin, @taxons) end |
#selected ⇒ Object
7 8 9 10 11 12 |
# File 'app/controllers/admin/supplier_taxons_controller.rb', line 7 def selected @supplier = load_supplier @taxons = @supplier.taxons @options = Taxon.all respond_with(:admin, @taxons) end |
#update_taxons ⇒ Object
47 48 49 50 51 52 53 |
# File 'app/controllers/admin/supplier_taxons_controller.rb', line 47 def update_taxons @supplier = Supplier.find params[:supplier_id] @supplier.taxons = [] @supplier.taxons.push(Taxon.all.select{|t| params[t.name.to_s] }) @supplier.save redirect_to :back, :notice => "Taxons successfully added" end |