Class: Admin::PostsController

Inherits:
BaseController
  • Object
show all
Defined in:
lib/railsbricks/assets/controllers/admin/posts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/railsbricks/assets/controllers/admin/posts_controller.rb', line 27

def create
  @post = Post.new(post_params)
  @post.user_id = current_user.id
  if @post.save
    redirect_to admin_posts_dashboard_path, notice: "New post published."
  else
    flash[:alert] = "Post not published."
    render :new
  end
end

#dashboardObject



10
11
12
13
# File 'lib/railsbricks/assets/controllers/admin/posts_controller.rb', line 10

def dashboard
  @published_post_count = Post.published.count
  @draft_post_count = Post.drafted.count
end

#destroyObject



51
52
53
54
# File 'lib/railsbricks/assets/controllers/admin/posts_controller.rb', line 51

def destroy
  @post.destroy
  redirect_to admin_posts_path, notice: "The post has been deleted."
end

#draftsObject



19
20
21
# File 'lib/railsbricks/assets/controllers/admin/posts_controller.rb', line 19

def drafts
  @posts = Post.drafted.page(params[:page]).per(50)
end

#editObject



38
39
# File 'lib/railsbricks/assets/controllers/admin/posts_controller.rb', line 38

def edit
end

#indexObject



15
16
17
# File 'lib/railsbricks/assets/controllers/admin/posts_controller.rb', line 15

def index
  @posts = Post.published.page(params[:page]).per(50)
end

#newObject



23
24
25
# File 'lib/railsbricks/assets/controllers/admin/posts_controller.rb', line 23

def new
  @post = Post.new
end

#updateObject



41
42
43
44
45
46
47
48
49
# File 'lib/railsbricks/assets/controllers/admin/posts_controller.rb', line 41

def update
  @post.slug = nil
  if @post.update(post_params)
    redirect_to admin_posts_dashboard_path, notice: "Post successfully edited."
  else
    flash[:alert] = "The post was not edited."
    render :edit
  end
end