Class: Kublog::PostsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/kublog/posts_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_user, #is_admin?, #require_admin

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
# File 'app/controllers/kublog/posts_controller.rb', line 24

def create
  @post = current_user.posts.build(params[:post])
  if @post.save
    redirect_to @post
  else
    @presenter = PostFormPresenter.new(@post)
    render 'new'
  end
end

#destroyObject



48
49
50
51
52
# File 'app/controllers/kublog/posts_controller.rb', line 48

def destroy
  @post = Post.find(params[:id])
  @post.destroy
  redirect_to posts_path
end

#editObject



34
35
36
# File 'app/controllers/kublog/posts_controller.rb', line 34

def edit
  @presenter = PostFormPresenter.new(Post.find(params[:id]))
end

#indexObject



6
7
8
9
10
11
12
13
# File 'app/controllers/kublog/posts_controller.rb', line 6

def index
  @presenter = PostsPresenter.new
  respond_to do |format|
    format.html { }
    format.atom { render :layout => false, :content_type => 'text/xml' }
    format.rss  { render :layout => false, :content_type => 'text/xml' }
  end
end

#newObject



15
16
17
# File 'app/controllers/kublog/posts_controller.rb', line 15

def new
  @presenter = PostFormPresenter.new(Post.new)
end

#showObject



19
20
21
22
# File 'app/controllers/kublog/posts_controller.rb', line 19

def show
  post = Post.find(params[:id])
  @presenter = PostPresenter.new(post)
end

#updateObject



38
39
40
41
42
43
44
45
46
# File 'app/controllers/kublog/posts_controller.rb', line 38

def update
  @post = Post.find(params[:id])
  if @post.update_attributes(params[:post])
    redirect_to @post
  else
    @presenter = PostFormPresenter.new(@post)
    render 'edit'
  end
end