Class: ObservationsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/observations_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) annotations

GET /annotations



81
82
83
84
# File 'app/controllers/observations_controller.rb', line 81

def annotations
  @object = @observation
  render '/shared/data/all/annotations'
end

- (Object) create

POST /observations POST /observations.json



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/observations_controller.rb', line 42

def create
  @observation = Observation.new(observation_params)

  respond_to do |format|
    if @observation.save
      format.html { redirect_to observation_path(@observation.metamorphosize), notice: 'Observation was successfully created.' }
      format.json { render :show, status: :created, location: @observation.metamorphosize }
    else
      format.html { render :new }
      format.json { render json: @observation.metamorphosize.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy

DELETE /observations/1 DELETE /observations/1.json



72
73
74
75
76
77
78
# File 'app/controllers/observations_controller.rb', line 72

def destroy
  @observation.destroy
  respond_to do |format|
    format.html { redirect_to observations_url, notice: 'Observation was successfully destroyed.' }
    format.json { head :no_content }
  end
end

- (Object) edit

GET /observations/1/edit



33
34
# File 'app/controllers/observations_controller.rb', line 33

def edit
end

- (Object) filter_params (private)



103
104
105
# File 'app/controllers/observations_controller.rb', line 103

def filter_params
  params.permit(:otu_id, :descriptor_id, :collection_object_id)
end

- (Object) index

GET /observations GET /observations.json



10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/observations_controller.rb', line 10

def index
  respond_to do |format|
    format.html do
      @recent_objects = Observation.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    end
    format.json {
      @observations = Observation.where(filter_params).with_project_id(sessions_current_project_id)
    }
  end
end

- (Object) list



36
37
38
# File 'app/controllers/observations_controller.rb', line 36

def list
  @observations = Observation.with_project_id(sessions_current_project_id).page(params[:page])
end

- (Object) new

GET /observations/new



28
29
30
# File 'app/controllers/observations_controller.rb', line 28

def new
  @observation = Observation.new
end

- (Object) observation_params (private)



92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/observations_controller.rb', line 92

def observation_params
  params.require(:observation).permit(
    :descriptor_id, :otu_id, :collection_object_id,
    :character_state_id, :frequency,
    :continuous_value, :continuous_unit,
    :sample_n, :sample_min, :sample_max, :sample_median, :sample_mean, :sample_units, :sample, :sample_standard_error,
    :presence,
    :description,
    :type)
end

- (Object) set_observation (private)



88
89
90
# File 'app/controllers/observations_controller.rb', line 88

def set_observation
  @observation = Observation.find(params[:id])
end

- (Object) show

GET /observations/1 GET /observations/1.json



24
25
# File 'app/controllers/observations_controller.rb', line 24

def show
end

- (Object) update

PATCH/PUT /observations/1 PATCH/PUT /observations/1.json



58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/observations_controller.rb', line 58

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