Class: Kuhsaft::Cms::BricksController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/kuhsaft/cms/bricks_controller.rb

Instance Method Summary collapse

Methods inherited from AdminController

#default_url_options, #set_content_locale

Instance Method Details

#createObject



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

def create
  @brick = params[:brick][:type].constantize.create(brick_params)
  @brick.image_size ||= ImageSize.all.first.name.to_s

  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



40
41
42
43
44
# File 'app/controllers/kuhsaft/cms/bricks_controller.rb', line 40

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

#newObject



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

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

#sortObject



46
47
48
49
50
51
52
53
# File 'app/controllers/kuhsaft/cms/bricks_controller.rb', line 46

def sort
  if params[:bricks].present?
    params[:bricks][:ids].split(',').each_with_index do |id, idx|
      Kuhsaft::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
33
34
35
36
37
38
# File 'app/controllers/kuhsaft/cms/bricks_controller.rb', line 24

def update
  @brick = Kuhsaft::Brick.find(params[:id])
  @brick.image_size ||= ImageSize.all.first.name.to_s
  params['brick'].delete('image_cache') if params['brick']['image']
  @brick.update_attributes(brick_params)
  #
  # rails will fall back to html if ajax can't be used
  # this is the case with the image brick, because ajax does not
  # support image uploads
  #
  respond_with @brick do |format|
    format.js
    format.html { redirect_to edit_cms_page_path(@brick.parents.first) }
  end
end