Sha256: 4bb01ef4fbea016e0f5d4b973f85be9d187e0a720d65a61763a3075d265f60a0

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

require_dependency "almanac/application_controller"

module Almanac
  class ImagesController < ApplicationController
    load_and_authorize_resource class: Almanac::Image
    respond_to :html

    before_filter :only => [:delete] do |controller|
      @image = Image.find(params[:id])
      @post = Post.find(params[:post_id])
    end

    def create
      @blog = Almanac::Blog.first
      @image = Image.new(params[:image])

      if params[:post_id] == "0"
        @post = Post.create( { :published => false, :author_id => current_user.id, :blog_id =>  @blog.id } )
      else
        @post = Post.find(params[:post_id])
      end

      @image.post = @post

      respond_with(@image) do |format|
        if @image.save
          format.html { redirect_to edit_post_path(@image.post), :notice => 'Image was successfully created.' }
        else
          format.html { redirect_to :back, :alert => 'Something went wrong, try again.' }
        end
      end
    end

    def destroy
      image_id = @image.id
      respond_to do |format|
        if @image.destroy
          format.html { redirect_to :root, :notice => 'Image was successfully deleted.' }
          format.js { render :nothing => true }
        else
          format.html { redirect_to post_path(@post), :alert => 'Something went wrong, try again.' }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
almanac-0.9.2 app/controllers/almanac/images_controller.rb
almanac-0.9.1 app/controllers/almanac/images_controller.rb
almanac-0.9.0 app/controllers/almanac/images_controller.rb