Class: Adminpanel::CategoriesController

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

Instance Method Summary collapse

Methods included from TwitterActions

#twitter_publish

Methods included from FacebookActions

#fb_choose_page, #fb_publish, #fb_save_token

Methods included from GalleryzableActions

#move_gallery_better, #move_gallery_worst

Methods included from SortableActions

#move_to_better, #move_to_worst

Methods included from RestActions

#edit, #show, #update

Methods included from SessionsHelper

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

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/adminpanel/categories_controller.rb', line 17

def create
  merge_params
  @resource_instance = @model.new(send(whitelisted_params))
  respond_to do |format|
    if @resource_instance.save
      format.html { redirect_to categories_path, flash: { success: I18n.t('action.save_success') } }
      format.js do
        if params[:currentcontroller].to_s == 'adminpanel/categories'
          # we are in categories controller
          render 'create', locals: { category: @resource_instance }
        elsif params[:belongs_request].present?
          # we are in other controller as a belongs_to, add option to select
          render 'adminpanel/templates/create_belongs_to', locals: { resource: @resource_instance }
        else
          # we are in other controller as a has_many, add checkbox
          render 'adminpanel/templates/create_has_many', locals: { resource: @resource_instance }
        end
      end
    else
      format.html { render 'adminpanel/templates/new' }
      format.js { render 'new' }
    end
  end
end

#destroyObject



42
43
44
45
# File 'app/controllers/adminpanel/categories_controller.rb', line 42

def destroy
  @resource_instance.destroy
  redirect_to categories_path
end

#indexObject



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

def index
  @categories = Category.all
end

#newObject



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

def new
  @resource_instance = @model.new
  respond_to do |format|
    format.html { render 'adminpanel/templates/new' }
    format.js { render }
  end
end