Class: CombinationsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/combinations_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 included from DataControllerConfiguration::ProjectDataControllerConfiguration

#polymorphic_filter_params

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) combination_params (private)

Never trust parameters from the scary internet, only allow the white list through.



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

def combination_params
  params.require(:combination).permit(:verbatim_name, :source_id, *Combination::APPLICABLE_RANKS.collect{|r| "#{r}_id".to_sym},
                                      origin_citation_attributes: [:id, :_destroy, :source_id, :pages],
                                     ) 
end

- (Object) create

POST /combinations.json



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/combinations_controller.rb', line 23

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

- (Object) destroy

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



53
54
55
56
57
58
59
# File 'app/controllers/combinations_controller.rb', line 53

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

- (Object) edit

GET /combinations/1/edit



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

def edit
  @combination.source = Source.new if !@combination.source
end

- (Object) new

GET /combinations/new



8
9
10
11
12
13
14
15
# File 'app/controllers/combinations_controller.rb', line 8

def new
  if params[:taxon_name_id]
    @protonym = Protonym.find(params[:taxon_name_id])
    @combination = Combination.new(@protonym.rank => @protonym, source: Source.new)
  else
    @combination = Combination.new
  end
end

- (Object) set_content (private)

Use callbacks to share common setup or constraints between actions.



63
64
65
66
# File 'app/controllers/combinations_controller.rb', line 63

def set_content
  @combination = Combination.with_project_id(sessions_current_project_id).find(params[:id])
  @recent_object = @combination 
end

- (Object) update

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



39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/combinations_controller.rb', line 39

def update
  respond_to do |format|
    if @combination.update(combination_params)
      format.html { redirect_to @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