Class: Miniblog::Admin::PostsController

Inherits:
BaseController show all
Defined in:
app/controllers/miniblog/admin/posts_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#after_post_is_saved

Methods inherited from Miniblog::ApplicationController

#method_missing

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Miniblog::ApplicationController

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/miniblog/admin/posts_controller.rb', line 18

def create
  @post = Post.new(post_params)
  @post.state = :drafted
  @post.author = current_user
  @post.regenerate_permalink
  if @post.save
    after_post_is_saved
    redirect_to miniblog.edit_admin_post_path(@post), notice: "Post created succesfully"
  else
    render action: :new
  end
end

#destroyObject



31
32
33
34
# File 'app/controllers/miniblog/admin/posts_controller.rb', line 31

def destroy
  @post.destroy
  redirect_to miniblog.admin_posts_path
end

#editObject



40
41
# File 'app/controllers/miniblog/admin/posts_controller.rb', line 40

def edit
end

#indexObject



12
13
14
15
16
# File 'app/controllers/miniblog/admin/posts_controller.rb', line 12

def index
  @state = params[:state]
  @posts = Post.for_admin_index
  @posts = @posts.with_state(@state) if @state
end

#newObject



6
7
8
9
10
# File 'app/controllers/miniblog/admin/posts_controller.rb', line 6

def new
  @post = Post.new
  @post.state = :drafted
  @post.author = current_user
end

#showObject



36
37
38
# File 'app/controllers/miniblog/admin/posts_controller.rb', line 36

def show
  @post = Post.includes(:assets).find(params[:id])
end

#updateObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/miniblog/admin/posts_controller.rb', line 43

def update
  handle_asset

  if @post.update_attributes(post_params)
    if @post.allowed_to_update_permalink?
      @post.regenerate_permalink
      @post.save!
    end
    after_post_is_saved
    flash[:notice] = "Post updated succesfully"
  end
  render action: :edit
end