Class: Helpdesk::Admin::FaqsController

Inherits:
BaseController show all
Defined in:
app/controllers/helpdesk/admin/faqs_controller.rb

Instance Method Summary collapse

Methods inherited from Helpdesk::ApplicationController

#default_url_options, #ensure_user

Instance Method Details

#createObject

POST /faqs POST /faqs.json



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/helpdesk/admin/faqs_controller.rb', line 67

def create
  @faq = Helpdesk::Faq.new(faq_params)

  respond_to do |format|
    if @faq.save
      format.html { redirect_to admin_faqs_url, notice: 'Faq was successfully created.' }
      format.json { render json: @faq, status: :created, location: @faq }
    else
      format.html { render action: "new" }
      format.json { render json: @faq.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /faqs/1 DELETE /faqs/1.json



99
100
101
102
103
104
105
106
107
# File 'app/controllers/helpdesk/admin/faqs_controller.rb', line 99

def destroy
  @faq = Helpdesk::Faq.find(params[:id])
  @faq.destroy

  respond_to do |format|
    format.html { redirect_to admin_faqs_url }
    format.json { head :no_content }
  end
end

#editObject

GET /faqs/1/edit



61
62
63
# File 'app/controllers/helpdesk/admin/faqs_controller.rb', line 61

def edit
  @faq = Helpdesk::Faq.find(params[:id])
end

#indexObject

GET /faqs GET /faqs.json



22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/helpdesk/admin/faqs_controller.rb', line 22

def index
  if params[:faqs] == 'active'
    @faqs = Helpdesk::Faq.roots.active
    render action: 'index'
  elsif params[:faqs] == 'inactive'
    @faqs = Helpdesk::Faq.inactive
    render action: 'inactive'
  else
    @faqs = Helpdesk::Faq.roots
    render action: 'index'
  end
end

#newObject

GET /faqs/new GET /faqs/new.json



48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/helpdesk/admin/faqs_controller.rb', line 48

def new
  @faq = Helpdesk::Faq.active.new
  if params[:faq] && params[:faq][:parent_id]
    @faq.parent_id = params[:faq][:parent_id]
  end

  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @faq }
  end
end

#showObject

GET /faqs/1 GET /faqs/1.json



37
38
39
40
41
42
43
44
# File 'app/controllers/helpdesk/admin/faqs_controller.rb', line 37

def show
  @faq = Helpdesk::Faq.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @faq }
  end
end

#sortObject



3
4
5
6
7
8
# File 'app/controllers/helpdesk/admin/faqs_controller.rb', line 3

def sort
  params[:faqs].each_with_index do |id, index|
    Helpdesk::Faq.find(id).update_column(:position, index+1)
  end
  render :nothing => true
end

#sortingObject



10
11
12
13
14
15
16
17
18
# File 'app/controllers/helpdesk/admin/faqs_controller.rb', line 10

def sorting
  if params[:id]=='all'

    @faqs = Helpdesk::Faq.roots
  else
    @faq = Helpdesk::Faq.find(params[:id])
    @faqs = @faq.children
  end
end

#updateObject

PUT /faqs/1 PUT /faqs/1.json



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/controllers/helpdesk/admin/faqs_controller.rb', line 83

def update
  @faq = Helpdesk::Faq.find(params[:id])

  respond_to do |format|
    if @faq.update_attributes(faq_params)
      format.html { redirect_to admin_faqs_url, notice: 'Faq was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: "edit" }
      format.json { render json: @faq.errors, status: :unprocessable_entity }
    end
  end
end