Class: Flms::PagesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Flms::PagesController
- Defined in:
- app/controllers/flms/pages_controller.rb
Instance Method Summary collapse
- #add_block ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #remove_block ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
- #update_blocks ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#add_block ⇒ Object
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 |
#create ⇒ Object
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 |
#destroy ⇒ Object
48 49 50 51 |
# File 'app/controllers/flms/pages_controller.rb', line 48 def destroy @page.destroy redirect_to pages_url end |
#edit ⇒ Object
27 28 29 |
# File 'app/controllers/flms/pages_controller.rb', line 27 def edit @available_blocks = Block.all - @page.blocks end |
#index ⇒ Object
9 10 11 |
# File 'app/controllers/flms/pages_controller.rb', line 9 def index @pages = Page.all end |
#new ⇒ Object
23 24 25 |
# File 'app/controllers/flms/pages_controller.rb', line 23 def new @page = Page.new end |
#remove_block ⇒ Object
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 |
#show ⇒ Object
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 |
#update ⇒ Object
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_blocks ⇒ Object
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 |