From edfb09930848026a2e5b0a620ec44b0a24282634 Mon Sep 17 00:00:00 2001 From: saurabhbhatia Date: Wed, 25 Dec 2013 20:34:53 +0800 Subject: [PATCH] Added Puma --- Gemfile | 1 + Gemfile.lock | 3 + .../api/v1/templates_controller.rb | 74 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 app/controllers/api/v1/templates_controller.rb diff --git a/Gemfile b/Gemfile index 33cd9a7..4873ae0 100644 --- a/Gemfile +++ b/Gemfile @@ -47,3 +47,4 @@ end # Use debugger # gem 'debugger', group: [:development, :test] +gem 'puma' diff --git a/Gemfile.lock b/Gemfile.lock index bb5bc34..cd0ee63 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,6 +87,8 @@ GEM optionable (0.2.0) origin (2.0.0) polyglot (0.3.3) + puma (2.7.1) + rack (>= 1.1, < 2.0) rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) @@ -150,6 +152,7 @@ DEPENDENCIES jquery-rails mongoid! mongoid_slug! + puma rails (= 4.0.2) sass-rails (~> 4.0.0) sdoc diff --git a/app/controllers/api/v1/templates_controller.rb b/app/controllers/api/v1/templates_controller.rb new file mode 100644 index 0000000..a4875de --- /dev/null +++ b/app/controllers/api/v1/templates_controller.rb @@ -0,0 +1,74 @@ +class TemplatesController < ApplicationController + before_action :set_template, only: [:show, :edit, :update, :destroy] + + # GET /templates + # GET /templates.json + def index + @templates = Template.all + end + + # GET /templates/1 + # GET /templates/1.json + def show + end + + # GET /templates/new + def new + @template = Template.new + end + + # GET /templates/1/edit + def edit + end + + # POST /templates + # POST /templates.json + def create + @template = Template.new(template_params) + + respond_to do |format| + if @template.save + format.html { redirect_to @template, notice: 'Template was successfully created.' } + format.json { render action: 'show', status: :created, location: @template } + else + format.html { render action: 'new' } + format.json { render json: @template.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /templates/1 + # PATCH/PUT /templates/1.json + def update + respond_to do |format| + if @template.update(template_params) + format.html { redirect_to @template, notice: 'Template was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: 'edit' } + format.json { render json: @template.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /templates/1 + # DELETE /templates/1.json + def destroy + @template.destroy + respond_to do |format| + format.html { redirect_to templates_url } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_template + @template = Template.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def template_params + params.require(:template).permit(:title, :author) + end +end