Skip to content

Instantly share code, notes, and snippets.

@trobrock
Last active January 3, 2016 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trobrock/a574870dff5fafbc2115 to your computer and use it in GitHub Desktop.
Save trobrock/a574870dff5fafbc2115 to your computer and use it in GitHub Desktop.
class CapsuleSerializer < ActiveModel::Serializer
attributes :id, :name, :state
end
class CapsulesController < ApplicationController
respond_to :html, :json
before_filter :authenticate_user!
# GET /capsules
# GET /capsules.json
def index
@capsules = Capsule.all
respond_with @capsules
# respond_to do |format|
# format.html
# format.json { render :json => @capsules }
# end
end
# GET /capsules/1
# GET /capsules/1.json
def show
@capsule = Capsule.find(params[:id])
end
# GET /capsules/new
def new
@capsule = Capsule.new(name: Capsule.bullshit_name)
end
# GET /capsules/1/edit
def edit
@capsule = Capsule.find(params[:id])
end
# POST /capsules
# POST /capsules.json
def create
@capsule = Capsule.new(capsule_params)
@capsule.owner = current_user
respond_to do |format|
if @capsule.save
@capsule.queue!
format.html { redirect_to capsules_path, notice: 'Capsule was successfully created.' }
format.json { render action: 'show', status: :created, location: @capsule }
else
format.html { render action: 'new' }
format.json { render json: @capsule.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /capsules/1
# PATCH/PUT /capsules/1.json
def update
@capsule = Capsule.find(params[:id])
respond_to do |format|
if @capsule.update(capsule_params)
format.html { redirect_to @capsule, notice: 'Capsule was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @capsule.errors, status: :unprocessable_entity }
end
end
end
# DELETE /capsules/1
# DELETE /capsules/1.json
def destroy
@capsule = Capsule.find(params[:id])
@capsule.destroy
respond_to do |format|
format.html { redirect_to capsules_url }
format.json { head :no_content }
end
end
private
def capsule_params
params.require(:capsule).permit(:name, :application, :connection)
end
end
class InstanceSerializer < ActiveModel::Serializer
attributes :id, :remote_id, :state, :size, :manifest
end
class InstancesController < ApplicationController
respond_to :json
before_filter :authenticate_user!
def index
@capsule = Capsule.find(params[:capsule_id])
respond_with @capsule.instances
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment