Class: Admin::PostTypesController

Inherits:
BaseController show all
Defined in:
app/controllers/admin/post_types_controller.rb

Instance Method Summary collapse

Methods included from BlogHelper

#blog_base_url, #this_blog

Instance Method Details

#createObject



15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/admin/post_types_controller.rb', line 15

def create
  @post_type = PostType.new(post_type_params)

  if @post_type.save
    flash[:notice] = I18n.t("admin.base.successfully_created",
                            name: PostType.model_name.human)
    redirect_to admin_post_types_url
  else
    render :index
  end
end

#destroyObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/admin/post_types_controller.rb', line 37

def destroy
  # Reset all Articles from the PostType we're destroying to the default PostType
  # Wrap it in a transaction for safety
  @post_type.transaction do
    Article.where(post_type: @post_type.permalink).find_each do |article|
      article.post_type = "read"
      article.save
    end
    @post_type.destroy
  end
  flash[:notice] = I18n.t("admin.base.successfully_deleted",
                          name: PostType.model_name.human)
  redirect_to admin_post_types_url
end

#editObject



11
12
13
# File 'app/controllers/admin/post_types_controller.rb', line 11

def edit
  @post_types = PostType.all
end

#indexObject



6
7
8
9
# File 'app/controllers/admin/post_types_controller.rb', line 6

def index
  @post_types = PostType.all
  @post_type = PostType.new
end

#updateObject



27
28
29
30
31
32
33
34
35
# File 'app/controllers/admin/post_types_controller.rb', line 27

def update
  if @post_type.update(post_type_params)
    flash[:notice] = I18n.t("admin.base.successfully_updated",
                            name: PostType.model_name.human)
    redirect_to admin_post_types_url
  else
    render :edit
  end
end