Class: Helios::Press::Admin::PostsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/helios/press/admin/posts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
# File 'app/controllers/helios/press/admin/posts_controller.rb', line 22

def create
  @post = Post.new(post_params)

  if @post.save
    redirect_to helios_press.edit_admin_post_path(@post), notice: "Post was successfully created."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



51
52
53
54
# File 'app/controllers/helios/press/admin/posts_controller.rb', line 51

def destroy
  @post.destroy
  redirect_to helios_press.admin_posts_path, notice: "Post was successfully deleted."
end

#editObject



32
33
# File 'app/controllers/helios/press/admin/posts_controller.rb', line 32

def edit
end

#indexObject



7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/helios/press/admin/posts_controller.rb', line 7

def index
  @posts = Post.reverse_sorted

  if params[:search].present?
    search_term = "%#{params[:search]}%"
    @posts = @posts.where("name ILIKE ? OR keywords ILIKE ?", search_term, search_term)
  end

  @posts = @posts.order(created_at: :desc)
end

#newObject



18
19
20
# File 'app/controllers/helios/press/admin/posts_controller.rb', line 18

def new
  @post = Post.new
end

#updateObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/helios/press/admin/posts_controller.rb', line 35

def update
  if params[:publish].present?
    update_params = post_params.merge(published: true)
    success_message = "Post was successfully published."
  else
    update_params = post_params
    success_message = "Post was successfully updated."
  end

  if @post.update(update_params)
    redirect_to helios_press.edit_admin_post_path(@post), notice: success_message
  else
    render :edit, status: :unprocessable_entity
  end
end