Class: PlateTemplatesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/plate_templates_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#block_api_access, #clean_params_from_check, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!

Instance Method Details

#createObject


26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/plate_templates_controller.rb', line 26

def create
  if params[:name].blank?
    flash[:error] = 'Please enter a name'
    redirect_to new_plate_template_path
    return
  end

  pattern = PlateTemplate.new
  pattern.update_params!(name: params[:name], user_id: current_user.id, wells: params[:empty_well], rows: params[:rows], cols: params[:cols])
  flash[:notice] = 'Template saved'
  redirect_to plate_templates_path
end

#destroyObject


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

def destroy
  pattern = PlateTemplate.find(params[:id])
  pattern.destroy

  respond_to do |format|
    format.html { redirect_to(plate_templates_path) }
  end
end

#editObject


39
40
41
42
43
# File 'app/controllers/plate_templates_controller.rb', line 39

def edit
  @pattern = PlateTemplate.find(params[:id])
  @plate_rows = Map::Coordinate.plate_length(@pattern.size)
  @plate_cols = Map::Coordinate.plate_width(@pattern.size)
end

#indexObject


7
8
9
# File 'app/controllers/plate_templates_controller.rb', line 7

def index
  @patterns = PlateTemplate.paginate(page: params[:page], per_page: 50)
end

#newObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/plate_templates_controller.rb', line 11

def new
  @plate_rows = params[:rows].to_i
  @plate_cols = params[:cols].to_i
  if @plate_rows == 0
    @plate_rows = Map::Coordinate.plate_length(96)
  end
  if @plate_cols == 0
    @plate_cols = Map::Coordinate.plate_width(96)
  end

  respond_to do |format|
    format.html # new.html.erb
  end
end

#updateObject


45
46
47
48
49
50
# File 'app/controllers/plate_templates_controller.rb', line 45

def update
  pattern = PlateTemplate.find(params[:id])
  pattern.update_params!(name: params[:name], user_id: current_user.id, wells: params[:empty_well], rows: params[:rows], cols: params[:cols])
  flash[:notice] = 'Template updated'
  redirect_to plate_templates_path
end