Class: CategoriesController

Inherits:
AdminController show all
Defined in:
app/controllers/categories_controller.rb

Instance Method Summary collapse

Methods inherited from AdminController

#clean_search, #require_admin, #sign_in

Methods inherited from OfficeController

#error

Methods included from OfficeHelper

#best_euros, #current_basket, #current_basket_or_nil, #current_clerk, #date, #euros, #has_ssl?, #markdown, #new_basket, #paginate, #shipping_method

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
# File 'app/controllers/categories_controller.rb', line 26

def create
  @category = Category.create(params_for_model)
  if @category.save
    flash.notice = t(:create_success, :model => "category") 
    redirect_to category_path(@category)
  else
    render :edit
  end
end

#destroyObject



55
56
57
58
# File 'app/controllers/categories_controller.rb', line 55

def destroy
  @category.destroy if @category.categories.empty?
  redirect_to categories_url 
end

#editObject



22
23
24
# File 'app/controllers/categories_controller.rb', line 22

def edit

end

#indexObject



6
7
8
9
10
11
# File 'app/controllers/categories_controller.rb', line 6

def index
  @q = Category.search(params[:q])
  @category_scope = @q.result(:distinct => true)
  @categories = @category_scope.includes(:products , :categories ).paginate( :page => params[:page],:per_page => 20).to_a
  @roots = Category.where(:category_id => nil).includes(:products , :categories ).to_a
end

#newObject



17
18
19
20
# File 'app/controllers/categories_controller.rb', line 17

def new
  @category = Category.new
  render :edit
end

#showObject



13
14
15
# File 'app/controllers/categories_controller.rb', line 13

def show
  @category = Category.where(:id => params[:id]).includes(:products).first
end

#updateObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/categories_controller.rb', line 36

def update
  online = @category.online
  if @category.update_attributes(params_for_model)
    notice = t(:update_success, :model => "category")
    if @category.online != online
      count = 0
      @category.products.each do |prod|
        prod.online = @category.online
        prod.save
        count += 1
      end
      notice += "<br> #{count} " + t(:products) + " " + (@category.online ? t(:made_online) : t(:made_offline))
    end
    redirect_to category_path(@category),  :notice => notice 
  else
    render :action => :edit 
  end
end