Sha256: 9c9d3b9f66c519f549231f51d74a0f35d3a2036404ee0b6526dd8f53995e58f8

Contents?: true

Size: 1.41 KB

Versions: 16

Compression:

Stored size: 1.41 KB

Contents

class SnippetsController < ApplicationController
  respond_to :json

  wrap_parameters :snippet, include: [:name, :content]
  before_filter :retrieve_snippet, only: [:update, :show, :destroy]

  def create
    respond_to do |format|
      format.json do
        snippet = Snippet.create(snippet_params.merge(user_id: current_user.id))

        if snippet.errors.any?
          render json: snippet.errors.full_messages, status: :unprocessable_entity
        else
          render json: snippet, status: :created
        end
      end
    end
  end

  def update
    respond_to do |format|
      format.json do
        @snippet.update_attributes!(snippet_params)

        if @snippet.errors.any?
          render json: @snippet.errors.full_messages, status: :unprocessable_entity
        else
          render json: @snippet
        end
      end
    end
  end

  def show
    respond_to do |format|
      format.json { render json: @snippet }
      format.html { render template: 'application/index' }
    end
  end

  def index
    respond_to do |format|
      format.html
      format.json { render json: Snippet.all }
    end
  end

  def destroy
    respond_to do |format|
      format.json do
        @snippet.destroy!
        render json: @snippet
      end
    end
  end

  private

  def retrieve_snippet
    @snippet = Snippet.find(params[:id])
  end

  def snippet_params
    params.require(:snippet).permit(:name, :content)
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
aleph_analytics-0.4.9.pre.dev app/controllers/snippets_controller.rb
aleph_analytics-0.4.8 app/controllers/snippets_controller.rb
aleph_analytics-0.4.7 app/controllers/snippets_controller.rb
aleph_analytics-0.4.4 app/controllers/snippets_controller.rb
aleph_analytics-0.4.2 app/controllers/snippets_controller.rb
aleph_analytics-0.4.1 app/controllers/snippets_controller.rb
aleph_analytics-0.3.0 app/controllers/snippets_controller.rb
aleph_analytics-0.2.0 app/controllers/snippets_controller.rb
aleph_analytics-0.1.0 app/controllers/snippets_controller.rb
aleph_analytics-0.0.6 app/controllers/snippets_controller.rb
aleph_analytics-0.0.5 app/controllers/snippets_controller.rb
aleph_analytics-0.0.4 app/controllers/snippets_controller.rb
aleph_analytics-0.0.3 app/controllers/snippets_controller.rb
aleph_analytics-0.0.2 app/controllers/snippets_controller.rb
aleph_analytics-0.0.1.alpha app/controllers/snippets_controller.rb
aleph_analytics-0.0.0.alpha app/controllers/snippets_controller.rb