Class: LeanCms::PostsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- LeanCms::PostsController
- Defined in:
- app/controllers/lean_cms/posts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
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. = 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 |
#destroy ⇒ Object
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 |
#edit ⇒ Object
42 43 |
# File 'app/controllers/lean_cms/posts_controller.rb', line 42 def edit end |
#index ⇒ Object
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 |
#new ⇒ Object
26 27 28 |
# File 'app/controllers/lean_cms/posts_controller.rb', line 26 def new @post = LeanCms::Post.new end |
#show ⇒ Object
23 24 |
# File 'app/controllers/lean_cms/posts_controller.rb', line 23 def show end |
#update ⇒ Object
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 |