Class: Admin::Blog::PostsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/blog/posts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



15
16
17
18
19
20
21
22
23
# File 'app/controllers/admin/blog/posts_controller.rb', line 15

def create
  @post.save!
  flash[:success] = 'Blog Post created'
  redirect_to :action => :edit, :id => @post

rescue ActiveRecord::RecordInvalid
  flash.now[:error] = 'Failed to create Blog Post'
  render :action => :new
end

#destroyObject



39
40
41
42
43
# File 'app/controllers/admin/blog/posts_controller.rb', line 39

def destroy
  @post.destroy
  flash[:success] = 'Blog Post removed'
  redirect_to :action => :index
end

#editObject



25
26
27
# File 'app/controllers/admin/blog/posts_controller.rb', line 25

def edit
  render
end

#indexObject



7
8
9
# File 'app/controllers/admin/blog/posts_controller.rb', line 7

def index
  @posts = @blog.posts.order(:published_at).page(params[:page])
end

#newObject



11
12
13
# File 'app/controllers/admin/blog/posts_controller.rb', line 11

def new
  render
end

#updateObject



29
30
31
32
33
34
35
36
37
# File 'app/controllers/admin/blog/posts_controller.rb', line 29

def update
  @post.update_attributes!(post_params)
  flash[:success] = 'Blog Post updated'
  redirect_to :action => :edit, :id => @post

rescue ActiveRecord::RecordInvalid
  flash.now[:error] = 'Failed to update Blog Post'
  render :action => :edit
end