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, #whitelist_constantize

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) annotations

GET /annotations



84
85
86
87
# File 'app/controllers/observations_controller.rb', line 84

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

- (Object) create

POST /observations POST /observations.json



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

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



75
76
77
78
79
80
81
# File 'app/controllers/observations_controller.rb', line 75

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



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

def edit
end

- (Object) filter_params (private)



106
107
108
# File 'app/controllers/observations_controller.rb', line 106

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
21
# 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



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

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

- (Object) new

GET /observations/new



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

def new
  @observation = Observation.new
end

- (Object) observation_params (private)



95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/observations_controller.rb', line 95

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)



91
92
93
# File 'app/controllers/observations_controller.rb', line 91

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

- (Object) show

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



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

def show
end

- (Object) update

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



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

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