Sha256: bda09b61799737b316e753d2b9b2c9e4da4b6656afe0d7925bd0f7c2b75915ba

Contents?: true

Size: 1.42 KB

Versions: 17

Compression:

Stored size: 1.42 KB

Contents

require_dependency "cm_page_builder/rails/application_controller"

module CmPageBuilder::Rails
  class PagesController < ApplicationController
    before_action :set_page, only: [:show, :edit, :update, :destroy]

    # GET /pages
    def index
      @pages = Page.all
    end

    # GET /pages/1
    def show
    end

    # GET /pages/new
    def new
      @page = Page.new
    end

    # GET /pages/1/edit
    def edit
    end

    # POST /pages
    def create
      components = page_params.delete('components')
      @page = Page.new(page_params)

      if @page.save
        @page.save_content(components)
        redirect_to @page, notice: 'Page was successfully created.'
      else
        render :new
      end
    end

    # PATCH/PUT /pages/1
    def update
      components = page_params.delete(:components)
      if @page.save_content(components)
        redirect_to @page, notice: 'Page was successfully updated.'
      else
        render :edit
      end
    end

    # DELETE /pages/1
    def destroy
      @page.destroy
      redirect_to pages_url, notice: 'Page was successfully destroyed.'
    end

    private
      # Use callbacks to share common setup or constraints between actions.
      def set_page
        @page = Page.find(params[:id])
      end

      # Only allow a trusted parameter "white list" through.
      def page_params
        params.require(:page).permit(:container_id, :container_type, :components)
      end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
cm_page_builder-0.2.3 app/controllers/cm_page_builder/rails/pages_controller.rb
cm_page_builder-0.2.2 app/controllers/cm_page_builder/rails/pages_controller.rb
cm_page_builder-rails-0.2.2 app/controllers/cm_page_builder/rails/pages_controller.rb
cm_page_builder-rails-0.2.1 app/controllers/cm_page_builder/rails/pages_controller.rb
cm_page_builder-rails-0.2.0 app/controllers/cm_page_builder/rails/pages_controller.rb
cm_page_builder-rails-0.1.12 app/controllers/cm_page_builder/rails/pages_controller.rb
cm_page_builder-rails-0.1.11 app/controllers/cm_page_builder/rails/pages_controller.rb
cm_page_builder-rails-0.1.10 app/controllers/cm_page_builder/rails/pages_controller.rb
cm_page_builder-rails-0.1.9 app/controllers/cm_page_builder/rails/pages_controller.rb
cm_page_builder-rails-0.1.8 app/controllers/cm_page_builder/rails/pages_controller.rb
cm_page_builder-rails-0.1.7 app/controllers/cm_page_builder/rails/pages_controller.rb
cm_page_builder-rails-0.1.6 app/controllers/cm_page_builder/rails/pages_controller.rb
cm_page_builder-rails-0.1.4 app/controllers/cm_page_builder/rails/pages_controller.rb
cm_page_builder-rails-0.1.3 app/controllers/cm_page_builder/rails/pages_controller.rb
cm_page_builder-rails-0.1.2 app/controllers/cm_page_builder/rails/pages_controller.rb
cm_page_builder-rails-0.1.1 app/controllers/cm_page_builder/rails/pages_controller.rb
cm_page_builder-rails-0.1.0 app/controllers/cm_page_builder/rails/pages_controller.rb