Class: Qbrick::Cms::BricksController

Inherits:
BackendController show all
Defined in:
app/controllers/qbrick/cms/bricks_controller.rb

Instance Method Summary collapse

Methods inherited from BackendController

#default_url_options, #reset_remembered_locale, #set_content_locale

Instance Method Details

#createObject



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

def create
  create_brick_from_type_param

  if @brick.valid?
    respond_with @brick do |format|
      format.js
      format.html { redirect_to edit_cms_page_path(@brick.parents.first) }
    end
  else
    render 'new'
  end
end

#destroyObject



34
35
36
37
38
# File 'app/controllers/qbrick/cms/bricks_controller.rb', line 34

def destroy
  @brick = Qbrick::Brick.find(params[:id])
  @parent_brick = @brick.brick_list
  @brick.destroy
end

#newObject



20
21
22
# File 'app/controllers/qbrick/cms/bricks_controller.rb', line 20

def new
  @brick = Qbrick::Brick.new(brick_params)
end

#sortObject



40
41
42
43
44
45
46
47
# File 'app/controllers/qbrick/cms/bricks_controller.rb', line 40

def sort
  if params[:bricks].present?
    params[:bricks][:ids].split(',').each_with_index do |id, idx|
      Qbrick::Brick.find(id).update_attribute(:position, idx.to_i + 1)
    end
  end
  render nothing: true
end

#updateObject



24
25
26
27
28
29
30
31
32
# File 'app/controllers/qbrick/cms/bricks_controller.rb', line 24

def update
  @brick = Qbrick::Brick.find(params[:id])
  @brick.update_attributes(brick_params)

  respond_with @brick do |format|
    format.js
    format.html { redirect_to edit_cms_page_path(@brick.parents.first) }
  end
end