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



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

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



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

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



59
60
61
# File 'app/controllers/helpdesk/admin/faqs_controller.rb', line 59

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
34
# File 'app/controllers/helpdesk/admin/faqs_controller.rb', line 22

def index
  if params[:faqs] == 'active'
    @faqs = Helpdesk::Faq.roots.active
  elsif params[:faqs] == 'inactive'
    @faqs = Helpdesk::Faq.roots.inactive
  else
    @faqs = Helpdesk::Faq.roots
  end
  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @faqs }
  end
end

#newObject

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



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

def new
  @faq = Helpdesk::Faq.new

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

#showObject

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



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

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



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

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