Class: SofaBlog::Admin::PostsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
# File 'app/controllers/sofa_blog/admin/posts_controller.rb', line 14

def create
  @post.save!
  flash[:notice] = 'Blog post created'
  redirect_to :action => :index
rescue ActiveRecord::RecordInvalid
  flash.now[:error] = 'Failed to create BlogPost'
  render :action => :new
end

#destroyObject



36
37
38
39
40
# File 'app/controllers/sofa_blog/admin/posts_controller.rb', line 36

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

#editObject



23
24
25
# File 'app/controllers/sofa_blog/admin/posts_controller.rb', line 23

def edit
  render
end

#indexObject



6
7
8
# File 'app/controllers/sofa_blog/admin/posts_controller.rb', line 6

def index
  @posts = SofaBlog::Post.order('created_at DESC')
end

#newObject



10
11
12
# File 'app/controllers/sofa_blog/admin/posts_controller.rb', line 10

def new
  @post.is_published ||= true
end

#updateObject



27
28
29
30
31
32
33
34
# File 'app/controllers/sofa_blog/admin/posts_controller.rb', line 27

def update
  @post.update_attributes!(params[:post])
  flash[:notice] = 'Blog post updated'
  redirect_to :action => :index
rescue ActiveRecord::RecordInvalid
  flash.now[:error] = 'Failed to update BlogPost'
  render :action => :edit
end