Class: Admin::SuppliersController
- Inherits:
-
BaseController
- Object
- BaseController
- Admin::SuppliersController
- Defined in:
- app/controllers/admin/suppliers_controller.rb
Instance Method Summary collapse
- #available ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #feature ⇒ Object
- #index ⇒ Object
- #line_items ⇒ Object
- #new ⇒ Object
- #remove ⇒ Object
- #select ⇒ Object
- #selected ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#available ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/admin/suppliers_controller.rb', line 81 def available if params[:q].blank? @available_suppliers = [] else @available_suppliers = Supplier.find(:all, :conditions => ['lower(name) LIKE ?', "%#{params[:q].downcase}%"]) end @available_suppliers.delete_if { |supplier| @product.supplier == supplier } respond_to do |format| format.html format.js {render :layout => false} end end |
#create ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'app/controllers/admin/suppliers_controller.rb', line 19 def create @supplier = Supplier.new(params[:supplier]) if @supplier.save redirect_to admin_suppliers_path, :notice => "New supplier created" else render "new" end end |
#destroy ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/admin/suppliers_controller.rb', line 37 def destroy @supplier = Supplier.find(params[:id]) @supplier.destroy flash[:notice] = "Supplier Successfully deleted." respond_with(@product) do |format| format.html { redirect_to collection_url } format.js do render :update do |page| page.redirect_to collection_url end end end end |
#edit ⇒ Object
32 33 34 35 |
# File 'app/controllers/admin/suppliers_controller.rb', line 32 def edit @supplier = Supplier.find(params[:id]) @supplier.images.build end |
#feature ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/admin/suppliers_controller.rb', line 61 def feature @supplier = Supplier.find(params[:supplier_id]) if @supplier.featured == true @supplier.featured = false else @supplier.featured = true end @supplier.save flash[:notice] = "change #{@supplier.title}'s feature status to #{@supplier.featured}" redirect_to admin_suppliers_path end |
#index ⇒ Object
5 6 7 8 9 10 11 |
# File 'app/controllers/admin/suppliers_controller.rb', line 5 def index if current_user.has_role?("admin") @suppliers = Supplier.all else @supplier = current_user.supplier end end |
#line_items ⇒ Object
73 74 75 |
# File 'app/controllers/admin/suppliers_controller.rb', line 73 def line_items @order = Order.find_by_number(params[:order_id]) end |
#new ⇒ Object
13 14 15 16 17 |
# File 'app/controllers/admin/suppliers_controller.rb', line 13 def new @supplier = Supplier.new() @supplier.images.build @status = true end |
#remove ⇒ Object
95 96 97 98 99 100 |
# File 'app/controllers/admin/suppliers_controller.rb', line 95 def remove @product.supplier = nil @product.save @supplier = @product.supplier render :layout => false end |
#select ⇒ Object
102 103 104 105 106 107 108 |
# File 'app/controllers/admin/suppliers_controller.rb', line 102 def select @supplier = Supplier.find_by_param!(params[:id]) @product.supplier = @supplier @product.save @supplier = @product.supplier render :layout => false end |
#selected ⇒ Object
77 78 79 |
# File 'app/controllers/admin/suppliers_controller.rb', line 77 def selected @supplier = @product.supplier end |
#show ⇒ Object
28 29 30 |
# File 'app/controllers/admin/suppliers_controller.rb', line 28 def show @supplier = Supplier.find(params[:id]) end |
#update ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/admin/suppliers_controller.rb', line 51 def update @supplier = Supplier.find(params[:id]) @status = false if @supplier.update_attributes(params[:supplier]) redirect_to edit_admin_supplier_path, :notice => "Supplier updated" else render "edit" end end |