app/controllers/flms/blocks_controller.rb in flms-0.0.3 vs app/controllers/flms/blocks_controller.rb in flms-0.1.0

- old
+ new

@@ -1,18 +1,26 @@ require_dependency "flms/application_controller" module Flms class BlocksController < ApplicationController layout 'flms/admin' - before_filter :authenticate_user! - before_filter :load_page + before_filter :authenticate_user!, except: [ :show ] before_filter :load_block, only: [:show, :edit, :update, :destroy] + layout :resolve_layout def index + @blocks = Block.all end def show + respond_to do |format| + format.plain_html { with_format('html') { render partial: 'flms/elements/block', + layout: 'flms/plain_styling', + locals: { block: @block, scroll_offset: 0 } } } + format.html + format.json { render json: @page } + end end def new @block = Block.new end @@ -20,48 +28,38 @@ def edit end def create @block = Block.new(params[:block]) + if @block.save - @block.pages << @page - redirect_to page_blocks_path(@page), notice: 'Block created.' + redirect_to blocks_path, notice: 'Block created.' else render action: "new" end end def update if @block.update_attributes(params[:block]) - redirect_to [@page, :blocks], notice: 'Block was successfully updated.' + redirect_to blocks_path, notice: 'Block was successfully updated.' else render action: "edit" end end - def update_all - 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 - def destroy @block.destroy - redirect_to page_blocks_path(@page), notice: 'Block deleted' + redirect_to blocks_path, notice: 'Block deleted' end + private - private - - def load_page - @page = Page.find_by_url params[:page_id] - end - def load_block @block = Block.find params[:id] end + + def resolve_layout + action_name == 'show' ? 'flms/public' : 'flms/admin' + end + end end