Class: Adminpanel::CategoriesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#handle_unverified_request, #set_model, #signed_in_user

Methods included from RestActionsHelper

#move_better, #move_worst, #show

Methods included from SessionsHelper

#current_user, #current_user=, #sign_in, #sign_out, #signed_in?

Instance Method Details

#create ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/adminpanel/categories_controller.rb', line 20

def create
  params.merge({:model_name => params[:model_name]}) if params[:model_name].present?
  params.merge({:model => params[:model]}) if params[:model].present?
  params.merge({:currentcontroller => params[:currentcontroller]}) if params[:currentcontroller].present?

  create! do |success, failure|
    success.html do
      flash[:success] = I18n.t("action.save_success")
      redirect_to categories_path
    end
    failure.html do
      set_collections
      render "shared/new"
    end
    success.js do
      if params[:currentcontroller] == 'adminpanel/categories'
        render 'create', :locals => {:category => resource}
      else
        render 'shared/create_has_many', :locals => {:resource => resource}
      end
    end
    failure.js do
      set_collections
      render "new", :locals => {:resource => resource }

    end
  end
end

#destroy ⇒ Object



72
73
74
75
76
77
78
# File 'app/controllers/adminpanel/categories_controller.rb', line 72

def destroy
  destroy! do |format|
    format.html do
      redirect_to categories_path
    end
  end
end

#edit ⇒ Object



49
50
51
52
53
54
55
56
# File 'app/controllers/adminpanel/categories_controller.rb', line 49

def edit
  edit! do |format|
    format.html do
      set_collections
      render "shared/edit"
    end
  end
end

#index ⇒ Object



5
6
7
# File 'app/controllers/adminpanel/categories_controller.rb', line 5

def index
  @categories = Category.all
end

#new ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'app/controllers/adminpanel/categories_controller.rb', line 9

def new
  set_collections
  new! do |format|
    format.html { render "shared/new" }
    format.js do
      render :locals => {:resource => resource}
    end
  end
end

#update ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/adminpanel/categories_controller.rb', line 58

def update
  update! do |success, failure|
    success.html do
      flash[:success] = I18n.t("action.save_success")
      # render "shared/index"
      redirect_to categories_path
    end
    failure.html do
      set_collections
      render "shared/edit"
    end
  end
end