Class: Vitrage::PiecesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/vitrage/pieces_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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
72
73
74
75
76
77
# File 'app/controllers/vitrage/pieces_controller.rb', line 30

def create
  wrong_params_here = false

  # check existance of params
  unless params[:kind] &&
         VitrageOwnersPiecesSlot::PIECE_CLASSES_STRINGS.include?(params[:kind]) &&
         params[:owner_type] &&
         params[:owner_id]
    wrong_params_here = true
  end

  # get the owner of vitrage
  unless wrong_params_here
    @owner = nil
    begin
      @owner = Object.const_get(params[:owner_type]).find params[:owner_id]
    rescue Exception => e
      wrong_params_here = true
    end
  end

  # create piece
  unless wrong_params_here
    @piece = VitragePieces.const_get(params[:kind]).new
    @piece.assign_attributes vitrage_piece_params
    wrong_params_here = true unless @piece.save
  end

  # create vitrage slot
  unless wrong_params_here
    @slot = VitrageOwnersPiecesSlot.new owner: @owner, piece: @piece
    unless @slot.save
      wrong_params_here = true
      @piece.destroy
    end
  end

  if wrong_params_here
    respond_to do |format|
      format.html { render text: "error", status: :unprocessable_entity }
    end
  else
    # respond_to do |format|
    #   format.html { render layout: false }
    # end
    render layout: false
  end
end

#destroyObject



87
88
89
90
91
92
93
94
# File 'app/controllers/vitrage/pieces_controller.rb', line 87

def destroy
  @slot = VitrageOwnersPiecesSlot.find params[:id]
  @slot.destroy

  respond_to do |format|
    format.html { render text: "" }
  end
end

#editObject



24
25
26
27
28
# File 'app/controllers/vitrage/pieces_controller.rb', line 24

def edit
  respond_to do |format|
    format.html { render layout: false }
  end
end

#newObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/vitrage/pieces_controller.rb', line 11

def new
  piece_class = params[:kind]
  unless piece_class &&
         VitrageOwnersPiecesSlot::PIECE_CLASSES_STRINGS.include?(piece_class)
    piece_class = VitrageOwnersPiecesSlot::PIECE_CLASSES_STRINGS.first
  end
  @piece = VitragePieces.const_get(piece_class).new
  
  respond_to do |format|
    format.html { render layout: false }
  end
end

#showObject



5
6
7
8
9
# File 'app/controllers/vitrage/pieces_controller.rb', line 5

def show
  respond_to do |format|
    format.html { render layout: false }
  end
end

#updateObject



79
80
81
82
83
84
85
# File 'app/controllers/vitrage/pieces_controller.rb', line 79

def update
  @piece.update vitrage_piece_params

  respond_to do |format|
    format.html { render action: "show", layout: false }
  end
end