Class: CombinationsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/combinations_controller.rb

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods included from RedirectHelper

#destroy_redirect

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification, #week_in_review_graphs

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#combination_paramsObject (private)



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/combinations_controller.rb', line 73

def combination_params
  p = ::Combination::APPLICABLE_RANKS.keys.inject(Hash.new){|hsh, r| hsh.merge "#{r}_taxon_name_relationship_attributes".to_sym => [:id, :_destroy] }
  params.require(:combination).permit(
    :verbatim_name,
    :verbatim_author,
    :year_of_publication,
    :source_id,
    *Combination::APPLICABLE_RANKS.keys.collect{ |r| "#{r}_id".to_sym},
    p,
    origin_citation_attributes: [:id, :_destroy, :source_id, :pages],
    roles_attributes: [
      :id, :_destroy, :type, :person_id, :position,
      person_attributes: [
        :last_name, :first_name, :suffix, :prefix
      ]
    ],
  )
end

#createObject

POST /combinations.json



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

def create
  @combination = Combination.new(combination_params)
  respond_to do |format|
    if @combination.save
      format.html { redirect_to taxon_names_path, notice: 'Combination was successfully created.' }
      format.json { render :show, status: :created, location: @combination.metamorphosize }
    else
      format.html { render :new }
      format.json { render json: @combination.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /combinations/1 DELETE /combinations/1.json



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

def destroy
  @combination.destroy
  respond_to do |format|
    format.html { redirect_to taxon_names_url }
    format.json { head :no_content }
  end
end

#editObject

GET /combinations/1/edit



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

def edit
  redirect_to new_combination_task_path(params.require(:id))
end

#indexObject

GET /combinations.json



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

def index
  @recent_objects = Combination.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(5)
end

#newObject

GET /combinations/new



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

def new
  redirect_to new_combination_task_path(params.permit(:id))
end

#set_combinationObject (private)



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

def set_combination
  @combination = Combination.with_project_id(sessions_current_project_id).find(params.require(:id))
  @recent_object = @combination
end

#showObject

GET /combinations/123.json



12
13
14
15
16
17
# File 'app/controllers/combinations_controller.rb', line 12

def show
  respond_to do |format|
    format.html { redirect_to taxon_name_path(params.require(:id)) }
    format.json { render :show, location: @combination.metamorphosize }
  end
end

#updateObject

PATCH/PUT /combinations/1 PATCH/PUT /combinations/1.json



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

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