Class: Crowdblog::Admin::PostsController

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

Instance Method Summary collapse

Methods inherited from Crowdblog::ApplicationController

#method_missing

Dynamic Method Handling

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

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
# File 'app/controllers/crowdblog/admin/posts_controller.rb', line 23

def create
  @post = Post.new(post_params)
  @post.author = current_user
  @post.regenerate_permalink
  if @post.save
    respond_with @post, :location => crowdblog.admin_posts_path
  end
end

#destroyObject



32
33
34
35
# File 'app/controllers/crowdblog/admin/posts_controller.rb', line 32

def destroy
  @post.destroy
  respond_with @post, :location => crowdblog.admin_posts_path
end

#editObject



44
45
# File 'app/controllers/crowdblog/admin/posts_controller.rb', line 44

def edit
end

#indexObject



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

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

#newObject



8
9
10
11
12
13
14
# File 'app/controllers/crowdblog/admin/posts_controller.rb', line 8

def new
  @post = Post.new
	@post.state = :drafted
  @post.author = current_user
  @post.save!
  redirect_to edit_admin_post_path(@post)
end

#showObject



37
38
39
40
41
42
# File 'app/controllers/crowdblog/admin/posts_controller.rb', line 37

def show
  @post = Post.includes(:assets).find(params[:id])
  respond_to do |format|
    format.json { render json: @post.to_json(include: :assets) }
  end
end

#updateObject



47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/crowdblog/admin/posts_controller.rb', line 47

def update
  @post.update_attributes(post_params)
  if @post.allowed_to_update_permalink?
    @post.regenerate_permalink
    @post.save!
  end

  respond_with @post do |format|
    format.html { redirect_to crowdblog.admin_posts_path }
  end
end