Class: ConfidencesController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/confidences_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 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) confidence_object (private)



100
101
102
# File 'app/controllers/confidences_controller.rb', line 100

def confidence_object
  params.require(:confidence_object_type).constantize.find(params.require(:confidence_object_id))
end

- (Object) confidence_object_update



57
58
59
60
61
62
63
64
65
# File 'app/controllers/confidences_controller.rb', line 57

def confidence_object_update 
  @confidence_object = confidence_object
  if @confidence_object.update(confidences_params)
    flash[:notice] = 'Successfully updated record.'
  else
    flash[:error] = "Error updating record: #{@confidence_object.errors.full_messages.join('; ')}."
  end
  redirect_to new_confidence_path(confidence_object_type: @confidence_object.class.name, confidence_object_id: @confidence_object.id.to_s)
end

- (Object) confidence_params (private)



96
97
98
# File 'app/controllers/confidences_controller.rb', line 96

def confidence_params
  params.require(:confidence).permit(:confidence_level_id, :confidence_object_id, :confidence_object_type)
end

- (Object) confidences_params (private)



104
105
106
107
108
# File 'app/controllers/confidences_controller.rb', line 104

def confidences_params
  params.require(:confidence_object).permit(
    confidences_attributes: [:_destroy, :id, :confidence_level_id]
  )
end

- (Object) create

POST /confidences POST /confidences.json



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

def create
  @confidence = Confidence.new(confidence_params)
  respond_to do |format|
    if @confidence.save
      format.html { redirect_to @confidence.confidence_object.metamorphosize, notice: 'Confidence was successfully created.' }
      format.json { render :show, status: :created, location: @confidence }
    else
      format.html { 
        redirect_to :back, notice: 'Confidence was NOT successfully created.'
      }
      format.json { render json: @confidence.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy

DELETE /confidences/1 DELETE /confidences/1.json



69
70
71
72
73
74
75
# File 'app/controllers/confidences_controller.rb', line 69

def destroy
  @confidence.destroy
  respond_to do |format|
    format.html { redirect_to confidences_url, notice: 'Confidence was successfully destroyed.' }
    format.json { head :no_content }
  end
end

- (Object) download

GET /confidences/download



86
87
88
# File 'app/controllers/confidences_controller.rb', line 86

def download
  send_data Download.generate_csv(Confidence.where(project_id: sessions_current_project_id)), type: 'text', filename: "confidences_#{DateTime.now.to_s}.csv"
end

- (Object) edit

GET /confidences/1/edit



19
20
# File 'app/controllers/confidences_controller.rb', line 19

def edit
end

- (Object) index

GET /confidences GET /confidences.json



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

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

- (Object) list



22
23
24
# File 'app/controllers/confidences_controller.rb', line 22

def list
  @confidences = Confidence.with_project_id(sessions_current_project_id).page(params[:page])
end

- (Object) new

GET /confidences/new



14
15
16
# File 'app/controllers/confidences_controller.rb', line 14

def new
  @confidence_object = confidence_object
end

- (Object) search



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

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

- (Object) set_confidence (private)



92
93
94
# File 'app/controllers/confidences_controller.rb', line 92

def set_confidence
  @confidence = Confidence.find(params[:id])
end

- (Object) update

PATCH/PUT /confidences/1 PATCH/PUT /confidences/1.json



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

def update
  respond_to do |format|
    if @confidence.update(confidence_params)
      format.html { redirect_to @confidence, notice: 'Confidence was successfully updated.' }
      format.json { render :show, status: :ok, location: @confidence }
    else
      format.html { render :edit }
      format.json { render json: @confidence.errors, status: :unprocessable_entity }
    end
  end
end