Class: HomesteadingPublisher::PostsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

require auth



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

def create
  @post = Post.new(post_params)
  if @post.save
    headers["Location"] = post_url(@post.params)
    redirect_to post_url(@post.params), notice: "Post was successfully created."
  else
    render action: "new"
  end
end

#destroyObject

require auth



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

def destroy
  @post.destroy
  redirect_to root_url
end

#editObject

require auth



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

def edit
  @page_title = "Editing Post - #{@post.name}"
end

#indexObject



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

def index
  @page_title = "Posts"

  @posts = Post.paginate(per_page: 5, page: params[:page])

  @posts = @posts.where(year:  params[:year])  if params[:year]
  @posts = @posts.where(month: params[:month]) if params[:month]
  @posts = @posts.where(day:   params[:day])   if params[:day]
end

#newObject

require auth



20
21
22
23
# File 'app/controllers/homesteading_publisher/posts_controller.rb', line 20

def new
  @page_title = "New Post"
  @post       = Post.new
end

#showObject



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

def show
  @page_title = @post.name
end

#updateObject

require auth



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

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