Class: UsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/users_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

#editObject


28
29
# File 'app/controllers/users_controller.rb', line 28

def edit
end

#indexObject


9
10
11
# File 'app/controllers/users_controller.rb', line 9

def index
  @users = User.all
end

#projectsObject


45
46
47
# File 'app/controllers/users_controller.rb', line 45

def projects
  @projects = @user.projects.page(params[:page])
end

#showObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/users_controller.rb', line 13

def show
  barcode_printers = BarcodePrinter.alphabetical.includes(:barcode_printer_type)
  @printer_list = barcode_printers.select { |printer| printer.barcode_printer_type.name == '96 Well Plate' }
  begin
    label_template = LabelPrinter::PmbClient.get_label_template_by_name(configatron.swipecard_pmb_template).fetch('data').first
    @label_template_id ||= label_template['id']
  rescue LabelPrinter::PmbException => e
    @label_template_id = nil
    flash[:error] = "Print My Barcode: #{e}"
  rescue NoMethodError
    @label_template_id = nil
    flash[:error] = 'Wrong PMB Label Template'
  end
end

#study_reportsObject


49
50
51
# File 'app/controllers/users_controller.rb', line 49

def study_reports
  @study_reports = StudyReport.for_user(@user).page(params[:page]).order(id: :desc)
end

#updateObject


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

def update
  params[:user].delete(:swipecard_code) if params[:user][:swipecard_code].blank?
  @user = User.find(params[:id])
  if @user.id == params[:id].to_i
    @user.update(params[:user])
  end
  if @user.save
    flash[:notice] = 'Profile updated'
  else
    flash[:error] = 'Problem updating profile.'
  end
  redirect_to action: :show, id: @user.id
end