-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathcombinations_controller.rb
92 lines (81 loc) · 2.85 KB
/
combinations_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
class CombinationsController < ApplicationController
include DataControllerConfiguration::ProjectDataControllerConfiguration
before_action :set_combination, only: [:update, :edit, :update, :destroy, :show]
# GET /combinations.json
def index
@recent_objects = Combination.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(5)
end
# GET /combinations/123.json
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
# GET /combinations/new
def new
redirect_to new_combination_task_path(params.permit(:id))
end
# GET /combinations/1/edit
def edit
redirect_to new_combination_task_path(params.require(:id))
end
# POST /combinations.json
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
# PATCH/PUT /combinations/1
# PATCH/PUT /combinations/1.json
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
# DELETE /combinations/1
# DELETE /combinations/1.json
def destroy
@combination.destroy
respond_to do |format|
format.html { redirect_to taxon_names_url }
format.json { head :no_content }
end
end
private
def set_combination
@combination = Combination.with_project_id(sessions_current_project_id).find(params.require(:id))
@recent_object = @combination
end
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
end