Class: Panda::CMS::Admin::PostsController
- Inherits:
-
BaseController
- Object
- Panda::Core::AdminController
- BaseController
- Panda::CMS::Admin::PostsController
- Defined in:
- app/controllers/panda/cms/admin/posts_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /admin/posts.
-
#edit ⇒ Object
Loads the post editor.
-
#index ⇒ Object
Get all posts.
-
#new ⇒ Object
Loads the add post form.
- #update ⇒ Object
Methods included from Panda::CMS::ApplicationHelper
#active_link?, #block_link_to, #component, #level_indent, #menu_indent, #nav_class, #nav_highlight_colour_classes, #panda_cms_editor, #panda_cms_form_with, #selected_nav_highlight_colour_classes, #table_indent, #title_tag
Instance Method Details
#create ⇒ Object
POST /admin/posts
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/panda/cms/admin/posts_controller.rb', line 34 def create @post = Panda::CMS::Post.new(post_params) @post.user_id = current_user.id @post.content = parse_content(post_params[:content]) # Parse the content before saving if @post.save Rails.logger.debug "Post saved successfully" redirect_to edit_admin_cms_post_path(@post.admin_param), notice: "The post was successfully created!" else Rails.logger.debug "Post save failed: #{@post.errors..inspect}" flash.now[:error] = @post.errors..join(", ") locals = setup_new_post_form(post: @post, preserved_content: post_params[:content]) render :new, locals: locals, status: :unprocessable_entity end end |
#edit ⇒ Object
Loads the post editor
28 29 30 31 |
# File 'app/controllers/panda/cms/admin/posts_controller.rb', line 28 def edit post.title, edit_admin_cms_post_path(post.admin_param) render :edit, locals: {post: post} end |
#index ⇒ Object
Get all posts
14 15 16 17 |
# File 'app/controllers/panda/cms/admin/posts_controller.rb', line 14 def index posts = Panda::CMS::Post..ordered render :index, locals: {posts: posts} end |
#new ⇒ Object
Loads the add post form
21 22 23 24 |
# File 'app/controllers/panda/cms/admin/posts_controller.rb', line 21 def new locals = setup_new_post_form render :new, locals: locals end |
#update ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/panda/cms/admin/posts_controller.rb', line 52 def update Rails.logger.debug "Current content: #{post.content.inspect}" Rails.logger.debug "New content from params: #{post_params[:content].inspect}" # Parse the content before updating update_params = post_params update_params[:content] = parse_content(post_params[:content]) update_params[:user_id] = current_user.id if post.update(update_params) Rails.logger.debug "Post updated successfully" post.title, edit_admin_cms_post_path(post.admin_param) flash[:success] = "The post was successfully updated" redirect_to edit_admin_cms_post_path(post.admin_param), status: :see_other else Rails.logger.debug "Post update failed: #{post.errors..inspect}" Rails.logger.debug "Preserving content: #{post_params[:content].inspect}" post.title.presence || "Edit Post", edit_admin_cms_post_path(post.admin_param) flash.now[:error] = post.errors..join(", ") render :edit, locals: { post: post, preserved_content: post_params[:content] }, status: :unprocessable_entity end end |