Class: PostsController

Inherits:
ApplicationController
  • Object
show all
Includes:
BlogController
Defined in:
app/controllers/posts_controller.rb

Instance Method Summary collapse

Methods included from BlogController

#index

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/posts_controller.rb', line 18

def create
  @post = Post.new(params[:post])
  @post.user = current_user
  
  if @post.save
    redirect_to @post, notice: t('general.form.successfully_created')
  else
    render :new
  end
end

#destroyObject



64
65
66
67
68
# File 'app/controllers/posts_controller.rb', line 64

def destroy
  @post.destroy
  
  redirect_to posts_path, notice: t('general.form.destroyed')
end

#editObject



29
30
# File 'app/controllers/posts_controller.rb', line 29

def edit
end

#newObject



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

def new
  @post = Post.new(params[:post])
end

#publishObject



40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/posts_controller.rb', line 40

def publish
  options = {}

  if @post.publish
    options[:notice] = t('posts.publish.successful')
  else  
    options[:alert] = t('posts.publish.unsuccessful')
  end
  
  redirect_to posts_path, options
end

#resourceObject



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

def resource
  @post
end

#showObject



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

def show
  @home_page_stylesheets = ['home_page/application', 'home_page_blog/posts']
  
  render layout: 'home_page_blog/application'
end

#unpublishObject



52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/posts_controller.rb', line 52

def unpublish
  options = {}

  if @post.unpublish
    options[:notice] = t('posts.unpublish.successful')
  else  
    options[:alert] = t('posts.unpublish.unsuccessful')
  end
  
  redirect_to posts_path, options
end

#updateObject



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

def update
  if @post.update_attributes(params[:post])
    redirect_to @post, notice: t('general.form.successfully_updated')
  else
    render :edit
  end
end