Sha256: d05da2c3f65e9a2a2b6792ba6bfa57f66905fd89c27c2433cd544e34d7cb8d21

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

require 'nokogiri'

module Tim
  class BaseImagesController < Tim::ApplicationController
    append_before_filter :set_template_xml, :only => [:create, :update]

    def index
      @base_images = Tim::BaseImage.all unless defined? @base_images
      respond_with @base_images
    end

    def show
      @base_image = Tim::BaseImage.find(params[:id]) unless defined? @base_image
      respond_with @base_image
    end

    def new
      @base_image = Tim::BaseImage.new
      respond_with @base_image
    end

    def edit
      @base_image = Tim::BaseImage.find(params[:id]) unless defined? @base_image
      respond_with @base_image
    end

    def create
      @base_image = Tim::BaseImage.new(params[:base_image]) unless defined? @base_image
      if @base_image.save
        flash[:notice] = "Successfully created Base Image"
      end
      respond_with @base_image
    end

    def update
      @base_image = Tim::BaseImage.find(params[:id]) unless defined? @base_image
      if @base_image.update_attributes(params[:base_image])
        flash[:notice] = "Successfully updated Base Image"
      end
      respond_with @base_image
    end

    def destroy
      @base_image = Tim::BaseImage.find(params[:id]) unless defined? @base_image
      @base_image.destroy
      respond_with(@base_image)
    end

    private
    # Handles the cases when the template xml is supplied within request
    def set_template_xml
      doc = ::Nokogiri::XML request.body.read
      if !doc.xpath("//base_image/template").empty?
        params[:base_image][:template] = { :xml => doc.xpath("//base_image/template").children.to_s}
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tim-0.1.2 app/controllers/tim/base_images_controller.rb
tim-0.1.1 app/controllers/tim/base_images_controller.rb
tim-0.0.1 app/controllers/tim/base_images_controller.rb