Class: LeanCms::PostsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @post = LeanCms::Post.new(post_params)
  @post.author = current_user
  @post.last_edited_by = current_user

  if @post.save
    redirect_to lean_cms_posts_path, notice: 'Post created successfully.'
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



55
56
57
58
# File 'app/controllers/lean_cms/posts_controller.rb', line 55

def destroy
  @post.destroy
  redirect_to lean_cms_posts_path, notice: 'Post deleted successfully.'
end

#editObject



42
43
# File 'app/controllers/lean_cms/posts_controller.rb', line 42

def edit
end

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/lean_cms/posts_controller.rb', line 8

def index
  @posts = LeanCms::Post.includes(:author, :last_edited_by)
                   .order(created_at: :desc)
  
  # Filter by content_type if provided
  if params[:content_type].present?
    case params[:content_type]
    when 'blog'
      @posts = @posts.blog_posts
    when 'portfolio'
      @posts = @posts.portfolio_items
    end
  end
end

#newObject



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

def new
  @post = LeanCms::Post.new
end

#showObject



23
24
# File 'app/controllers/lean_cms/posts_controller.rb', line 23

def show
end

#updateObject



45
46
47
48
49
50
51
52
53
# File 'app/controllers/lean_cms/posts_controller.rb', line 45

def update
  @post.last_edited_by = current_user

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