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

#clear_project_and_user_variables, #digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #intercept_api, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #notice_user, #project_matches, #record_not_found, #set_project_and_user_variables, #set_project_from_params, #token_authenticate

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) create

POST /preparation_types POST /preparation_types.json



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/preparation_types_controller.rb', line 30

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



60
61
62
63
64
65
66
# File 'app/controllers/preparation_types_controller.rb', line 60

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



81
82
83
# File 'app/controllers/preparation_types_controller.rb', line 81

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

- (Object) edit

GET /preparation_types/1/edit



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

def edit
end

- (Object) index

GET /preparation_types GET /preparation_types.json



8
9
10
11
12
# File 'app/controllers/preparation_types_controller.rb', line 8

def index
  @preparation_types = PreparationType.all
  @recent_objects = PreparationType.order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



68
69
70
# File 'app/controllers/preparation_types_controller.rb', line 68

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

- (Object) new

GET /preparation_types/new



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

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.



109
110
111
# File 'app/controllers/preparation_types_controller.rb', line 109

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

- (Object) search



72
73
74
75
76
77
78
# File 'app/controllers/preparation_types_controller.rb', line 72

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.



103
104
105
106
# File 'app/controllers/preparation_types_controller.rb', line 103

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



16
17
# File 'app/controllers/preparation_types_controller.rb', line 16

def show
end

- (Object) update

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



46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/preparation_types_controller.rb', line 46

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