Class: PersonalBlog::PostsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /posts



31
32
33
34
35
36
37
38
39
# File 'app/controllers/personal_blog/posts_controller.rb', line 31

def create
  @post = Post.new(post_params)

  if @post.save
    redirect_to @post, notice: 'Post was successfully created.'
  else
    render :new
  end
end

#destroyObject

DELETE /posts/1



51
52
53
54
# File 'app/controllers/personal_blog/posts_controller.rb', line 51

def destroy
  @post.destroy
  redirect_to posts_url, notice: 'Post was successfully destroyed.'
end

#editObject

GET /posts/1/edit



27
28
# File 'app/controllers/personal_blog/posts_controller.rb', line 27

def edit
end

#indexObject

GET /posts



9
10
11
12
13
14
15
# File 'app/controllers/personal_blog/posts_controller.rb', line 9

def index
  if params[:tag]
    @posts = Post.tagged_with(params[:tag])
  else
    @posts = Post.all
  end
end

#newObject

GET /posts/new



22
23
24
# File 'app/controllers/personal_blog/posts_controller.rb', line 22

def new
  @post = Post.new
end

#showObject

GET /posts/1



18
19
# File 'app/controllers/personal_blog/posts_controller.rb', line 18

def show
end

#updateObject

PATCH/PUT /posts/1



42
43
44
45
46
47
48
# File 'app/controllers/personal_blog/posts_controller.rb', line 42

def update
  if @post.update(post_params)
    redirect_to @post, notice: 'Post was successfully updated.'
  else
    render :edit
  end
end