Class: ClassificationsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/classifications_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /classifications POST /classifications.json



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/classifications_controller.rb', line 68

def create
  @classification = Classification.new(classification_params)

  respond_to do |format|
    if @classification.save
      format.html { redirect_to @classification, notice: t('controller.successfully_created', model: t('activerecord.models.classification')) }
      format.json { render json: @classification, status: :created, location: @classification }
    else
      @classification_types = ClassificationType.all
      format.html { render action: "new" }
      format.json { render json: @classification.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /classifications/1 DELETE /classifications/1.json



100
101
102
103
104
105
106
107
108
# File 'app/controllers/classifications_controller.rb', line 100

def destroy
  @classification = Classification.find(params[:id])
  @classification.destroy

  respond_to do |format|
    format.html { redirect_to classifications_url, notice: t('controller.successfully_deleted', model: t('activerecord.models.classification')) }
    format.json { head :no_content }
  end
end

#editObject

GET /classifications/1/edit



62
63
64
# File 'app/controllers/classifications_controller.rb', line 62

def edit
  @classification_types = ClassificationType.all
end

#indexObject

GET /classifications GET /classifications.json



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/classifications_controller.rb', line 8

def index
  search = Sunspot.new_search(Classification)
  query = params[:query].to_s.strip
  unless query.blank?
    @query = query.dup
    search.build do
      fulltext query
    end
  end
  unless params[:mode] == 'add'
    subject = @subject
    classification_type = @classification_type
    search.build do
      with(:subject_ids).equal_to subject.id if subject
      with(:classification_type_id).equal_to classification_type.id if classification_type
    end
  end

  page = params[:page] || 1
  search.query.paginate(page.to_i, Classification.default_per_page)
  @classifications = search.execute!.results

  session[:params] = {} unless session[:params]
  session[:params][:classification] = params

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @classifications }
  end
end

#newObject

GET /classifications/new GET /classifications/new.json



50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/classifications_controller.rb', line 50

def new
  @classification_types = ClassificationType.all
  @classification = Classification.new
  @classification.classification_type = @classification_type

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

#showObject

GET /classifications/1 GET /classifications/1.json



41
42
43
44
45
46
# File 'app/controllers/classifications_controller.rb', line 41

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

#updateObject

PUT /classifications/1 PUT /classifications/1.json



85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/controllers/classifications_controller.rb', line 85

def update
  respond_to do |format|
    if @classification.update(classification_params)
      format.html { redirect_to @classification, notice: t('controller.successfully_updated', model: t('activerecord.models.classification')) }
      format.json { head :no_content }
    else
      @classification_types = ClassificationType.all
      format.html { render action: "edit" }
      format.json { render json: @classification.errors, status: :unprocessable_entity }
    end
  end
end