Class: Flms::PagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/flms/pages_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#with_format

Instance Method Details

#add_blockObject



53
54
55
56
57
# File 'app/controllers/flms/pages_controller.rb', line 53

def add_block
  @block = Block.find params[:block][:id]
  @page.blocks << @block
  redirect_to edit_page_path(@page), notice: 'Block added.'
end

#createObject



31
32
33
34
35
36
37
38
# File 'app/controllers/flms/pages_controller.rb', line 31

def create
  @page = Page.new params[:page]
  if @page.save
    redirect_to pages_path, notice: 'Page was successfully created.'
  else
    render action: "new"
  end
end

#destroyObject



48
49
50
51
# File 'app/controllers/flms/pages_controller.rb', line 48

def destroy
  @page.destroy
  redirect_to pages_url
end

#editObject



27
28
29
# File 'app/controllers/flms/pages_controller.rb', line 27

def edit
  @available_blocks = Block.all - @page.blocks
end

#indexObject



9
10
11
# File 'app/controllers/flms/pages_controller.rb', line 9

def index
  @pages = Page.all
end

#newObject



23
24
25
# File 'app/controllers/flms/pages_controller.rb', line 23

def new
  @page = Page.new
end

#remove_blockObject



59
60
61
62
63
# File 'app/controllers/flms/pages_controller.rb', line 59

def remove_block
  @block = Block.find params[:block_id]
  @page.blocks.delete @block
  redirect_to edit_page_path(@page), notice: 'Block removed.'
end

#showObject



13
14
15
16
17
18
19
20
21
# File 'app/controllers/flms/pages_controller.rb', line 13

def show
  respond_to do |format|
    format.plain_html { with_format('html') { render partial: 'flms/elements/page', formats: [:html],
                                                     layout: 'flms/plain_styling',
                                                     locals: { page: @page } } }
    format.html
    format.json { render json: @page }
  end
end

#updateObject



40
41
42
43
44
45
46
# File 'app/controllers/flms/pages_controller.rb', line 40

def update
  if @page.update_attributes params[:page]
    redirect_to pages_path, notice: 'Page was successfully updated.'
  else
    render action: "edit"
  end
end

#update_blocksObject



65
66
67
68
69
70
71
72
73
# File 'app/controllers/flms/pages_controller.rb', line 65

def update_blocks
  params[:block_data].each_with_index do |block_data, pos|
    position = @page.position_for_block block_data[:id].to_i
    position.active = block_data[:active]
    position.ordering = pos
    position.save!
  end
  render text: ''
end