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

#set_content_locale, #url_options

Instance Method Details

#createObject



7
8
9
10
11
# File 'app/controllers/kuhsaft/cms/bricks_controller.rb', line 7

def create
  @brick = params[:brick][:type].constantize.new(params[:brick])
  @brick.image_size = ImageSize.all.first.name.to_s
  @brick.save(:validate => false)
end

#destroyObject



28
29
30
31
32
# File 'app/controllers/kuhsaft/cms/bricks_controller.rb', line 28

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

#sortObject



34
35
36
37
38
39
40
41
# File 'app/controllers/kuhsaft/cms/bricks_controller.rb', line 34

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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/kuhsaft/cms/bricks_controller.rb', line 13

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

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