Class: SerialsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::SharedDataControllerConfiguration
Defined in:
app/controllers/serials_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::SharedDataControllerConfiguration

#set_is_shared_data_model

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) autocomplete

TODO:

Some extra code here, str defined with extra param, used in label_html. Verify correct.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/controllers/serials_controller.rb', line 82

def autocomplete
  @serials = Serial.find_for_autocomplete(params)

  data = @serials.collect do |t|
    str = ApplicationController.helpers.serial_autocomplete_tag(t, params[:term])
    { id: t.id,
      label: ApplicationController.helpers.serial_tag(t),
      response_values: {
        params[:method] => t.id
      },
      label_html: str
    }
  end

  render json: data
end

- (Object) create

POST /serials POST /serials.json



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/serials_controller.rb', line 35

def create
  @serial = Serial.new(serial_params)

  respond_to do |format|
    if @serial.save
      format.html { redirect_to @serial, notice: "Serial '#{@serial.name}' was successfully created." }
      format.json { render action: 'show', status: :created, location: @serial }
    else
      format.html { render action: 'new' }
      format.json { render json: @serial.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy

DELETE /serials/1 DELETE /serials/1.json



65
66
67
68
69
70
71
# File 'app/controllers/serials_controller.rb', line 65

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

- (Object) download

GET /serials/download



100
101
102
# File 'app/controllers/serials_controller.rb', line 100

def download
  send_data Serial.generate_download(Serial.all), type: 'text', filename: "serials_#{DateTime.now}.csv"
end

- (Object) edit

GET /serials/1/edit



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

def edit
end

- (Object) index

GET /serials GET /serials.json



9
10
11
12
# File 'app/controllers/serials_controller.rb', line 9

def index
  @recent_objects = Serial.order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



14
15
16
# File 'app/controllers/serials_controller.rb', line 14

def list
  @serials = Serial.order(:id).page(params[:page])
end

- (Object) new

GET /serials/new



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

def new
  @serial = Serial.new
end

- (Object) search



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

def search
  if params[:id].blank?
    redirect_to serials_path, notice: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    redirect_to serial_path(params[:id])
  end
end

- (Object) serial_params (private)

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



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/controllers/serials_controller.rb', line 113

def serial_params
  params.require(:serial).permit(:name,
                                 :publisher,
                                 :place_published,
                                 :primary_language_id,
                                 :first_year_of_issue,
                                 :last_year_of_issue,
                                 alternate_values_attributes: [
                                   :id,
                                   :value,
                                   :type,
                                   :language_id,
                                   :alternate_value_object_type,
                                   :alternate_value_object_id,
                                   :alternate_value_object_attribute,
                                   :_destroy
                                 ])
end

- (Object) set_serial (private)

Use callbacks to share common setup or constraints between actions.



107
108
109
110
# File 'app/controllers/serials_controller.rb', line 107

def set_serial
  @serial = Serial.find(params[:id])
  @recent_object = @serial
end

- (Object) show

GET /serials/1 GET /serials/1.json



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

def show
  # TODO: put computation here for displaying alternate values?
end

- (Object) update

PATCH/PUT /serials/1 PATCH/PUT /serials/1.json



51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/serials_controller.rb', line 51

def update
  respond_to do |format|
    if @serial.update(serial_params)
      format.html { redirect_to @serial, notice: 'Serial was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: 'edit' }
      format.json { render json: @serial.errors, status: :unprocessable_entity }
    end
  end
end