Class: ClassificationsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ClassificationsController
- Defined in:
- app/controllers/classifications_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /classifications POST /classifications.json.
-
#destroy ⇒ Object
DELETE /classifications/1 DELETE /classifications/1.json.
-
#edit ⇒ Object
GET /classifications/1/edit.
- #get_classification_type ⇒ Object
-
#index ⇒ Object
GET /classifications GET /classifications.json.
-
#new ⇒ Object
GET /classifications/new GET /classifications/new.json.
-
#show ⇒ Object
GET /classifications/1 GET /classifications/1.json.
-
#update ⇒ Object
PUT /classifications/1 PUT /classifications/1.json.
Instance Method Details
#create ⇒ Object
POST /classifications POST /classifications.json
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/classifications_controller.rb', line 69 def create @classification = Classification.new(params[:classification]) 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 |
#destroy ⇒ Object
DELETE /classifications/1 DELETE /classifications/1.json
101 102 103 104 105 106 107 108 109 |
# File 'app/controllers/classifications_controller.rb', line 101 def destroy @classification = Classification.find(params[:id]) @classification.destroy respond_to do |format| format.html { redirect_to classifications_url } format.json { head :no_content } end end |
#edit ⇒ Object
GET /classifications/1/edit
63 64 65 |
# File 'app/controllers/classifications_controller.rb', line 63 def edit @classification_types = ClassificationType.all end |
#get_classification_type ⇒ Object
111 112 113 |
# File 'app/controllers/classifications_controller.rb', line 111 def get_classification_type @classification_type = ClassificationType.find(params[:classification_type_id]) rescue nil end |
#index ⇒ Object
GET /classifications GET /classifications.json
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 38 |
# File 'app/controllers/classifications_controller.rb', line 9 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 |
#new ⇒ Object
GET /classifications/new GET /classifications/new.json
51 52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/classifications_controller.rb', line 51 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 |
#show ⇒ Object
GET /classifications/1 GET /classifications/1.json
42 43 44 45 46 47 |
# File 'app/controllers/classifications_controller.rb', line 42 def show respond_to do |format| format.html # show.html.erb format.json { render :json => @classification } end end |
#update ⇒ Object
PUT /classifications/1 PUT /classifications/1.json
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/controllers/classifications_controller.rb', line 86 def update respond_to do |format| if @classification.update_attributes(params[:classification]) 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 |