Class: Gluttonberg::Admin::Content::BlogsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/gluttonberg/admin/content/blogs_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



34
35
36
37
38
39
40
41
42
# File 'app/controllers/gluttonberg/admin/content/blogs_controller.rb', line 34

def create
  @blog = Blog.new(params[:gluttonberg_blog])
  if @blog.save
    flash[:notice] = "The blog was successfully created."
    redirect_to admin_blogs_path
  else
    render :edit
  end
end

#deleteObject



64
65
66
67
68
69
70
71
# File 'app/controllers/gluttonberg/admin/content/blogs_controller.rb', line 64

def delete
  display_delete_confirmation(
    :title      => "Delete Blog '#{@blog.name}'?",
    :url        => admin_blog_path(@blog),
    :return_url => admin_blogs_path, 
    :warning    => "This will delete all the articles that belong to this blog"
  )
end

#destroyObject



73
74
75
76
77
78
79
80
81
# File 'app/controllers/gluttonberg/admin/content/blogs_controller.rb', line 73

def destroy
  if @blog.delete
    flash[:notice] = "The blog was successfully deleted."
    redirect_to admin_blogs_path
  else
    flash[:error] = "There was an error deleting the blog."
    redirect_to admin_blogs_path
  end
end

#editObject



44
45
46
47
48
49
# File 'app/controllers/gluttonberg/admin/content/blogs_controller.rb', line 44

def edit
  unless params[:version].blank?
    @version = params[:version]  
    @blog.revert_to(@version)
  end
end

#indexObject



14
15
16
17
18
19
# File 'app/controllers/gluttonberg/admin/content/blogs_controller.rb', line 14

def index
  @blogs = Blog.paginate(:per_page => Gluttonberg::Setting.get_setting("number_of_per_page_items"), :page => params[:page])
  if @blogs && @blogs.size == 1
    redirect_to admin_blog_articles_path(@blogs.first)
  end
end

#newObject



30
31
32
# File 'app/controllers/gluttonberg/admin/content/blogs_controller.rb', line 30

def new
  @blog = Blog.new
end

#showObject



21
22
23
24
25
26
27
28
# File 'app/controllers/gluttonberg/admin/content/blogs_controller.rb', line 21

def show
  @blog = Blog.find(params[:id])
  if @blog
    redirect_to admin_blog_articles_path(@blog)
  else
    redirect_to admin_blog_path
  end
end

#updateObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/gluttonberg/admin/content/blogs_controller.rb', line 51

def update
  @blog.current_slug = @blog.slug
  @blog.assign_attributes(params[:gluttonberg_blog])
  @blog.previous_slug = @blog.current_slug if @blog.slug_changed?
  if @blog.save
    flash[:notice] = "The blog was successfully updated."
    redirect_to admin_blogs_path
  else
    flash[:error] = "Sorry, The blog could not be updated."
    render :edit
  end
end