Sha256: 8dffbc11572fe403fc3565102c1a1dc1d6ddc90c3f5c644eb6e92b68e4a3becc

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 KB

Contents

require_dependency "front_end_builds/application_controller"

module FrontEndBuilds
  class AppsController < ApplicationController
    before_filter :set_app , :only => [:show, :destroy]
    respond_to :json

    def index
      apps = App.includes(:recent_builds)

      respond_with({
        apps: apps.map(&:serialize),
        builds: apps.map(&:recent_builds)
                  .flat_map(&:to_a)
                  .map(&:serialize)
      })
    end

    def show
      respond_with({
        app: @app.serialize,
        builds: @app.recent_builds.map(&:serialize)
      })
    end

    def create
      @app = FrontEndBuilds::App.new( use_params(:app_create_params) )

      if @app.save!
        respond_with(
          { app: @app.serialize },
          location: nil
        )
      else
        respond_with(
          { errors: @app.errors },
          status: :unprocessable_entity
        )
      end
    end

    def destroy
      if @app.destroy
        respond_with(
          { app: { id: @app.id } },
          location: nil
        )
      else
        respond_with(
          {errors: @app.errors},
          status: :unprocessable_entity
        )
      end
    end

    private

    def set_app
      @app = FrontEndBuilds::App.find(params[:id])
    end

    def app_create_params_rails_3
      params[:app].slice(:name)
    end

    def app_create_params_rails_4
      params.require(:app).permit(
        :name
      )
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
front_end_builds-0.0.18 app/controllers/front_end_builds/apps_controller.rb
front_end_builds-0.0.17 app/controllers/front_end_builds/apps_controller.rb
front_end_builds-0.0.16 app/controllers/front_end_builds/apps_controller.rb
front_end_builds-0.0.15 app/controllers/front_end_builds/apps_controller.rb