Class: PiccoBlog::PostsController

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

Instance Method Summary collapse

Instance Method Details

#admin_listObject



24
25
26
27
# File 'app/controllers/picco_blog/posts_controller.rb', line 24

def admin_list
  @posts = Post.all.order('id desc')
  @posts = @posts.page params[:page]
end

#createObject

POST /posts



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

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



69
70
71
72
# File 'app/controllers/picco_blog/posts_controller.rb', line 69

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

#editObject

GET /posts/1/edit



45
46
# File 'app/controllers/picco_blog/posts_controller.rb', line 45

def edit
end

#indexObject

GET /posts



11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/picco_blog/posts_controller.rb', line 11

def index
  if params[:tag].present?
    @posts = Post.visible.tagged_with(params[:tag]).order('id desc')
  elsif params[:search].present?
    @posts = Post.visible.search(params[:search]).order("id desc")
  else
    @posts = Post.visible.order('id desc')
  end

  @posts = @posts.page params[:page]
  @title = "Blog"
end

#newObject

GET /posts/new



40
41
42
# File 'app/controllers/picco_blog/posts_controller.rb', line 40

def new
  @post = Post.new
end

#showObject

GET /posts/1



30
31
32
33
34
35
36
37
# File 'app/controllers/picco_blog/posts_controller.rb', line 30

def show
  if request.path != post_path(@post)
    redirect_to @post, status: :moved_permanently
  end
  
  @title = @post.title
  @meta_description = @post.excerpt.truncate(300).strip
end

#updateObject

PATCH/PUT /posts/1



60
61
62
63
64
65
66
# File 'app/controllers/picco_blog/posts_controller.rb', line 60

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