Class: PandaCms::Admin::PostsController
- Inherits:
-
PandaCms::ApplicationController
- Object
- ActionController::Base
- PandaCms::ApplicationController
- PandaCms::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 inherited from PandaCms::ApplicationController
#add_breadcrumb, #authenticate_admin_user!, #authenticate_user!, #breadcrumbs, #current_user, #set_current_request_details, #user_signed_in?
Methods included from PandaCms::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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/panda_cms/admin/posts_controller.rb', line 33 def create post = PandaCms::Post.new(post_params) post.user_id = current_user.id # TODO: Support post tags properly post.tag = PandaCms::PostTag.find_or_create_by(tag: "Uncategorised") if post.save redirect_to edit_admin_post_path(post), notice: "The post was successfully created." else flash[:error] = "There was an error creating the post." locals = setup_new_post_form(post: post) render :new, locals: locals, status: :unprocessable_entity end end |
#edit ⇒ Object
Loads the post editor
27 28 29 30 |
# File 'app/controllers/panda_cms/admin/posts_controller.rb', line 27 def edit post.title, edit_admin_post_path(post) render :edit, locals: {post: post, url: admin_post_path(post)} end |
#index ⇒ Object
Get all posts
13 14 15 16 |
# File 'app/controllers/panda_cms/admin/posts_controller.rb', line 13 def index posts = PandaCms::Post.with_user.order(:published_at) render :index, locals: {posts: posts} end |
#new ⇒ Object
Loads the add post form
20 21 22 23 |
# File 'app/controllers/panda_cms/admin/posts_controller.rb', line 20 def new locals = setup_new_post_form render :new, locals: locals end |
#update ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/panda_cms/admin/posts_controller.rb', line 51 def update post.title, edit_admin_post_path(post) if post.update(post_params) redirect_to edit_admin_post_path(post), status: :see_other, flash: {success: "This post was successfully updated!"} else flash[:error] = "There was an error updating the post." render :edit, status: :unprocessable_entity end end |