Class: PreparationTypesController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::SharedDataControllerConfiguration
Defined in:
app/controllers/preparation_types_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#is_data_controller, #is_task_controller, #meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary (collapse)

Methods included from DataControllerConfiguration::SharedDataControllerConfiguration

#set_is_shared_data_model

Methods inherited from ApplicationController

#digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #project_matches, #record_not_found, #set_project_from_params

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Methods included from InterceptApi

#intercept_api, #token_authenticate

Instance Method Details

- (Object) create

POST /preparation_types POST /preparation_types.json



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/preparation_types_controller.rb', line 35

def create
  @preparation_type = PreparationType.new(preparation_type_params)

  respond_to do |format|
    if @preparation_type.save
      format.html { redirect_to @preparation_type, notice: "Preparation type '#{@preparation_type.name}' was successfully created." }
      format.json { render action: 'show', status: :created, location: @preparation_type }
    else
      format.html { render action: 'new' }
      format.json { render json: @preparation_type.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy

DELETE /preparation_types/1 DELETE /preparation_types/1.json



65
66
67
68
69
70
71
# File 'app/controllers/preparation_types_controller.rb', line 65

def destroy
  @preparation_type.destroy
  respond_to do |format|
    format.html { redirect_to preparation_types_url }
    format.json { head :no_content }
  end
end

- (Object) download

GET /preparation_types/download



86
87
88
89
90
# File 'app/controllers/preparation_types_controller.rb', line 86

def download
  send_data(Download.generate_csv(PreparationType.all),
            type: 'text',
            filename: "preparation_types_#{DateTime.now}.csv")
end

- (Object) edit

GET /preparation_types/1/edit



30
31
# File 'app/controllers/preparation_types_controller.rb', line 30

def edit
end

- (Object) index

GET /preparation_types GET /preparation_types.json



8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/preparation_types_controller.rb', line 8

def index
  respond_to do |format|
    @preparation_types = PreparationType.all
    format.html do
      @recent_objects = PreparationType.order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    end
    format.json {}
  end
end

- (Object) list



73
74
75
# File 'app/controllers/preparation_types_controller.rb', line 73

def list
  @preparation_types = PreparationType.order(:id).page(params[:page]) #.per(10) #.per(3)
end

- (Object) new

GET /preparation_types/new



25
26
27
# File 'app/controllers/preparation_types_controller.rb', line 25

def new
  @preparation_type = PreparationType.new
end

- (Object) preparation_type_params (private)

Never trust parameters from the scary internet, only allow the white list through.



117
118
119
# File 'app/controllers/preparation_types_controller.rb', line 117

def preparation_type_params
  params.require(:preparation_type).permit(:name, :definition)
end

- (Object) search



77
78
79
80
81
82
83
# File 'app/controllers/preparation_types_controller.rb', line 77

def search
  if params[:id].blank?
    redirect_to preparation_type_path, notice: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    redirect_to preparation_type_path(params[:id])
  end
end

- (Object) set_preparation_type (private)

Use callbacks to share common setup or constraints between actions.



111
112
113
114
# File 'app/controllers/preparation_types_controller.rb', line 111

def set_preparation_type
  @preparation_type = PreparationType.find(params[:id])
  @recent_object = @preparation_type
end

- (Object) show

GET /preparation_types/1 GET /preparation_types/1.json



21
22
# File 'app/controllers/preparation_types_controller.rb', line 21

def show
end

- (Object) update

PATCH/PUT /preparation_types/1 PATCH/PUT /preparation_types/1.json



51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/preparation_types_controller.rb', line 51

def update
  respond_to do |format|
    if @preparation_type.update(preparation_type_params)
      format.html { redirect_to @preparation_type, notice: 'Preparation type was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: 'edit' }
      format.json { render json: @preparation_type.errors, status: :unprocessable_entity }
    end
  end
end