Class: Reference::DataSetsController
- Inherits:
-
BaseController
- Object
- Crud::BaseController
- BaseController
- Reference::DataSetsController
- Defined in:
- app/controllers/reference/data_sets_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
Public: RESTful resource create operation.
-
#destroy ⇒ Object
Public: RESTful resource destroy operation.
-
#edit ⇒ Object
Public: RESTful resource edit operation.
-
#index ⇒ Object
Public: RESTful resource index operation.
-
#new ⇒ Object
Public: RESTful resource new operation.
-
#show ⇒ Object
Public: RESTful resource show operation.
-
#update ⇒ Object
Public: RESTful resource update operation.
Methods inherited from BaseController
Instance Method Details
#create ⇒ Object
Public: RESTful resource create operation.
POST /reference/data_sets
POST /reference/data_sets.json
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/reference/data_sets_controller.rb', line 72 def create @data_set = DataSet.new(params[:data_set]) respond_to do |format| if @data_set.save # Note: we don't reload reference data yet, since a new DataSet has no content at first creation. format.html { redirect_to [:reference, @data_set], notice: 'Data Set was successfully created.' } format.json { render json: @data_set, status: :created, location: @data_set } else format.html do # Set breadcrumbs again, otherwise they'd be lost on render of 'new' template: :data_set render action: "new" end format.json { render json: @data_set.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
Public: RESTful resource destroy operation.
DELETE /reference/data_sets/1
DELETE /reference/data_sets/1.json
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/controllers/reference/data_sets_controller.rb', line 116 def destroy retrieve_data_set # Create the path to the reference file associated with this about to be deleted data set, # so that we can delete it: reference_filename = File.join(Rails.root, "data/reference/DataSets/#{@data_set.name}.js") # TODO: DRY up these path references to somewhere central @data_set.destroy # Now that the DataSet has been removed from the database, go ahead and delete the # reference file: File.delete(reference_filename) if File.exists?(reference_filename) Reference::DataTypes.reload # Update all of our reference data, given the destroyed DataSet respond_to do |format| format.html { redirect_to [:reference, :data_sets], notice: 'Data Set was successfully destroyed.' } format.json { head :no_content } end end |
#edit ⇒ Object
Public: RESTful resource edit operation.
GET /reference/data_sets/1/edit
63 64 65 |
# File 'app/controllers/reference/data_sets_controller.rb', line 63 def edit retrieve_data_set end |
#index ⇒ Object
Public: RESTful resource index operation. We additionally handle filtering the index based on any search parameters present.
GET /reference/data_sets
GET /reference/data_sets.json
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/reference/data_sets_controller.rb', line 12 def index #params[:search] = nil if (params[:clear]) #search_string = params[:search] #@data_sets = DataSet.search(search_string) @data_sets = DataSet.all :data_sets respond_to do |format| format.html # index.html.erb format.json { render json: @data_sets } end end |
#new ⇒ Object
Public: RESTful resource new operation. We pre-fill the new DataSet with default options.
GET /reference/data_sets/new
GET /reference/data_sets/new.json
49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/reference/data_sets_controller.rb', line 49 def new @data_set = DataSet.new(DataSet.) :data_set respond_to do |format| format.html # new.html.erb format.json { render json: @data_set } end end |
#show ⇒ Object
Public: RESTful resource show operation.
GET /reference/data_sets/1
GET /reference/data_sets/1.json
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/reference/data_sets_controller.rb', line 30 def show retrieve_data_set if @data_set respond_to do |format| format.html # show.html.erb format.json { render json: @data_set } end else redirect_to [:reference, :data_sets], alert: "DataSet with id #{params[:id]} not found. You have been redirected to the DataSets listing." end end |
#update ⇒ Object
Public: RESTful resource update operation.
PUT /reference/data_sets/1
PUT /reference/data_sets/1.json
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/controllers/reference/data_sets_controller.rb', line 96 def update retrieve_data_set respond_to do |format| if @data_set.update_attributes(params[:data_set]) Reference::DataTypes.reload # Update all of our reference data, given the updated DataSet format.html { redirect_to [:reference, @data_set], notice: 'Data Set was successfully updated.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @data_set.errors, status: :unprocessable_entity } end end end |