Sha256: ed56ba58b496258624118cf7ae3e521457a7094c7c265c541b273337398c2b16

Contents?: true

Size: 1.1 KB

Versions: 11

Compression:

Stored size: 1.1 KB

Contents

require_dependency "hicube/application_controller"

module Hicube
  class ContentsController < BaseController

    before_action :load_resource, except: [
      :create,
      :index,
      :new
    ]

    before_filter :load_resources, :only => [
      :index,
    ]

    # Must be called after load_recource filter.
    before_filter :check_resource_params, :only => [
      :create,
      :update,
    ]

    def update
      logger.debug "Updating Pages with #{params}"
      @content.update_attributes content_params

      @content.save!
      respond_to do |format|
        format.json { render json: true }
      end
    rescue Mongoid::Errors::Validations => e
      respond_to do |format|
        format.json { render json: false }
      end 
    end

    private

    def content_params
      params.require(:content).permit(:name, :body)
    end

    # Nested attributes are currently not handled in basecontroller
    def load_resource
      @page = Hicube::Page.unscoped.find(params[:page_id])
      @content = @page.content.find_or_create_by(name: params[:id])
    end

    def load_resources

    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
hicube-0.0.11 app/controllers/hicube/contents_controller.rb
hicube-0.0.10 app/controllers/hicube/contents_controller.rb
hicube-0.0.9 app/controllers/hicube/contents_controller.rb
hicube-0.0.8 app/controllers/hicube/contents_controller.rb
hicube-0.0.7 app/controllers/hicube/contents_controller.rb
hicube-0.0.6 app/controllers/hicube/contents_controller.rb
hicube-0.0.5 app/controllers/hicube/contents_controller.rb
hicube-0.0.4 app/controllers/hicube/contents_controller.rb
hicube-0.0.3 app/controllers/hicube/contents_controller.rb
hicube-0.0.2 app/controllers/hicube/contents_controller.rb
hicube-0.0.1 app/controllers/hicube/contents_controller.rb