Class: LoansController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- LoansController
- Includes:
- DataControllerConfiguration::ProjectDataControllerConfiguration
- Defined in:
- app/controllers/loans_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)
- - (Object) autocomplete
-
- (Object) create
POST /loans POST /loans.json.
-
- (Object) destroy
DELETE /loans/1 DELETE /loans/1.json.
-
- (Object) download
GET /loans/download.
-
- (Object) edit
GET /loans/1/edit.
-
- (Object) index
GET /loans GET /loans.json.
- - (Object) list
- - (Object) loan_params private
-
- (Object) new
GET /loans/new.
- - (Object) recipient_form
- - (Object) search
- - (Object) set_loan private
-
- (Object) show
GET /loans/1 GET /loans/1.json.
-
- (Object) update
PATCH/PUT /loans/1 PATCH/PUT /loanss/1.json.
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
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, #whitelist_constantize
Methods included from ProjectsHelper
#project_link, #project_tag, #projects_list, #projects_search_form
Instance Method Details
- (Object) autocomplete
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/controllers/loans_controller.rb', line 85 def autocomplete @loans = Loan.find_for_autocomplete(params.merge(project_id: sessions_current_project_id)) data = @loans.collect do |t| {id: t.id, label: ApplicationController.helpers.loan_tag(t), response_values: { params[:method] => t.id }, label_html: ApplicationController.helpers.loan_tag(t) } end render json: data end |
- (Object) create
POST /loans POST /loans.json
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/loans_controller.rb', line 30 def create @loan = Loan.new(loan_params) respond_to do |format| if @loan.save format.html { redirect_to @loan, notice: 'Loan was successfully created.' } format.json { render :show, status: :created, location: @loan } else format.html { render :new } format.json { render json: @loan.errors, status: :unprocessable_entity } end end end |
- (Object) destroy
DELETE /loans/1 DELETE /loans/1.json
65 66 67 68 69 70 71 |
# File 'app/controllers/loans_controller.rb', line 65 def destroy @loan.destroy respond_to do |format| format.html { redirect_to loans_url } format.json { head :no_content } end end |
- (Object) download
GET /loans/download
102 103 104 |
# File 'app/controllers/loans_controller.rb', line 102 def download send_data Download.generate_csv(Loan.where(project_id: sessions_current_project_id)), type: 'text', filename: "loans_#{DateTime.now}.csv" end |
- (Object) edit
GET /loans/1/edit
25 26 |
# File 'app/controllers/loans_controller.rb', line 25 def edit end |
- (Object) index
GET /loans GET /loans.json
9 10 11 12 |
# File 'app/controllers/loans_controller.rb', line 9 def index @recent_objects = Loan.includes(:loan_items, :identifiers).recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10) render '/shared/data/all/index' end |
- (Object) list
73 74 75 |
# File 'app/controllers/loans_controller.rb', line 73 def list @loans = Loan.includes(:identifiers).with_project_id(sessions_current_project_id).order("CAST(coalesce(identifiers.identifier, '0') AS integer) DESC").references(:identifiers).page(params[:page]) #.per(10) #.per(3) end |
- (Object) loan_params (private)
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/controllers/loans_controller.rb', line 113 def loan_params params.require(:loan).permit(:date_requested, :request_method, :date_sent, :date_received, :date_return_expected, :recipient_person_id, :recipient_address, :recipient_email, :recipient_phone, :recipient_country, :supervisor_person_id, :supervisor_email, :supervisor_phone, :date_closed, :recipient_honorarium, :lender_address, :clone_from, loan_items_attributes: [ :_destroy, :id, :global_entity, :loan_item_object_type, :loan_item_object_id, :position, :total, :disposition, :date_, :date_returned_jquery ], roles_attributes: [ :id, :_destroy, :type, :person_id, :position, person_attributes: [ :last_name, :first_name, :suffix, :prefix]], ) end |
- (Object) new
GET /loans/new
20 21 22 |
# File 'app/controllers/loans_controller.rb', line 20 def new @loan = Loan.new(params.permit(:clone_from)) end |
- (Object) recipient_form
44 45 46 |
# File 'app/controllers/loans_controller.rb', line 44 def recipient_form render layout: 'us_letter' end |
- (Object) search
77 78 79 80 81 82 83 |
# File 'app/controllers/loans_controller.rb', line 77 def search if params[:id].blank? redirect_to loan_path, notice: 'You must select an item from the list with a click or tab press before clicking show.' else redirect_to loan_path(params[:id]) end end |
- (Object) set_loan (private)
108 109 110 111 |
# File 'app/controllers/loans_controller.rb', line 108 def set_loan @loan = Loan.with_project_id(sessions_current_project_id).find(params[:id]) @recent_object = @loan end |
- (Object) show
GET /loans/1 GET /loans/1.json
16 17 |
# File 'app/controllers/loans_controller.rb', line 16 def show end |
- (Object) update
PATCH/PUT /loans/1 PATCH/PUT /loanss/1.json
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/loans_controller.rb', line 50 def update respond_to do |format| if @loan.update(loan_params) @loan.reload format.html { redirect_to @loan, notice: 'Loan was successfully updated.' } format.json { render :show, status: :ok, location: @loan } else format.html { render :edit } format.json { render json: @loan.errors, status: :unprocessable_entity } end end end |