Class: PinboardItemsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/pinboard_items_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 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) create

POST /pinboard_items POST /pinboard_items.json



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/pinboard_items_controller.rb', line 7

def create
  @pinboard_item = PinboardItem.new(pinboard_item_params.merge(user_id: sessions_current_user_id))
  respond_to do |format|
    if @pinboard_item.save
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Pinboard item was successfully created.')}
      format.json { render json: @pinboard_item, status: :created, location: @pinboard_item }
      format.js {}
    else
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: "Couldn't pin this item! Is it already there?")}
      format.json { render json: @pinboard_item.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy

DELETE /pinboard_items/1 DELETE /pinboard_items/1.json



45
46
47
48
49
50
51
52
# File 'app/controllers/pinboard_items_controller.rb', line 45

def destroy
  @pinboard_item.destroy
  respond_to do |format|
    format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Pinboard item was successfully destroyed.')}
    format.json { head :no_content }
    format.js {}
  end
end

- (Object) pinboard_item_params (private)



59
60
61
# File 'app/controllers/pinboard_items_controller.rb', line 59

def pinboard_item_params
  params.require(:pinboard_item).permit(:pinned_object_id, :pinned_object_type, :user_id, :is_inserted, :is_cross_project, :inserted_count)
end

- (Object) set_pinboard_item (private)



55
56
57
# File 'app/controllers/pinboard_items_controller.rb', line 55

def set_pinboard_item
  @pinboard_item = PinboardItem.with_project_id(sessions_current_project_id).find(params[:id])
end

- (Object) update

PATCH/PUT /pinboard_items/1 PATCH/PUT /pinboard_items/1.json



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

def update
  respond_to do |format|
    if @pinboard_item.update(pinboard_item_params)
      format.html { redirect_to @pinboard_item, notice: 'Pinboard items was successfully updated.' }
      format.json { render :show, location: @pinboard_item }
      format.js {}
    else
      format.html { render action: 'edit' }
      format.json { render json: @pinboard_item.errors, status: :unprocessable_entity }
      format.js {}
    end
  end
end

- (Object) update_position

Stub a “reorder” method



38
39
40
41
# File 'app/controllers/pinboard_items_controller.rb', line 38

def update_position
  PinboardItem.reorder(params.require(:order))
  render nothing: true
end