Class: PinboardItemsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/pinboard_items_controller.rb

Instance Method Summary collapse

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form

Methods included from Api::Intercept

#intercept_api

Instance Method Details

#createObject

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 action: :show, 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

#destroyObject

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

#pinboard_item_paramsObject (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

#set_pinboard_itemObject (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

#updateObject

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

#update_positionObject

Stub a “reorder” method



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

def update_position
  PinboardItem.reorder_by(params.require(:order))
  head :ok
end