Class: Almanac::ImagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/almanac/images_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#set_blog, #set_current_author

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/almanac/images_controller.rb', line 13

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

#destroyObject



34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/almanac/images_controller.rb', line 34

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