-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathcards_controller.rb
More file actions
71 lines (56 loc) · 1.64 KB
/
Copy pathcards_controller.rb
File metadata and controls
71 lines (56 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class CardsController < ApplicationController
include FilterScoped
before_action :set_board, only: %i[ create ]
before_action :set_card, only: %i[ show edit update destroy ]
before_action :redirect_if_drafted, only: :show
before_action :ensure_permission_to_administer_card, only: %i[ destroy ]
def index
set_page_and_extract_portion_from @filter.cards
end
def create
respond_to do |format|
format.html do
card = Current.user.draft_new_card_in(@board)
redirect_to card_draft_path(card)
end
format.json do
@card = @board.cards.create! card_params.merge(creator: Current.user, status: "published")
render :show, status: :created, location: card_path(@card, format: :json)
end
end
end
def show
end
def edit
end
def update
@card.update! card_params
respond_to do |format|
format.turbo_stream
format.json { render :show }
end
end
def destroy
@card.destroy!
respond_to do |format|
format.html { redirect_to @card.board, notice: "Card deleted" }
format.json { head :no_content }
end
end
private
def set_board
@board = Current.user.boards.find params[:board_id]
end
def set_card
@card = Current.user.accessible_cards.find_by!(number: params[:id])
end
def redirect_if_drafted
redirect_to card_draft_path(@card) if @card.drafted?
end
def ensure_permission_to_administer_card
head :forbidden unless Current.user.can_administer_card?(@card)
end
def card_params
params.expect(card: [ :title, :description, :image, :created_at, :last_active_at ])
end
end