class Admin::PostsController
Public Instance Methods
create()
click to toggle source
# File lib/railsbricks/assets/controllers/admin/posts_controller.rb, line 27 def create @post = Post.new(post_params) @post.user_id = current_user.id if @post.save redirect_to admin_posts_dashboard_path, notice: "New post published." else flash[:alert] = "Post not published." render :new end end
dashboard()
click to toggle source
# File lib/railsbricks/assets/controllers/admin/posts_controller.rb, line 10 def dashboard @published_post_count = Post.published.count @draft_post_count = Post.drafted.count end
destroy()
click to toggle source
# File lib/railsbricks/assets/controllers/admin/posts_controller.rb, line 51 def destroy @post.destroy redirect_to admin_posts_path, notice: "The post has been deleted." end
drafts()
click to toggle source
# File lib/railsbricks/assets/controllers/admin/posts_controller.rb, line 19 def drafts @posts = Post.drafted.page(params[:page]).per(50) end
edit()
click to toggle source
# File lib/railsbricks/assets/controllers/admin/posts_controller.rb, line 38 def edit end
index()
click to toggle source
# File lib/railsbricks/assets/controllers/admin/posts_controller.rb, line 15 def index @posts = Post.published.page(params[:page]).per(50) end
new()
click to toggle source
# File lib/railsbricks/assets/controllers/admin/posts_controller.rb, line 23 def new @post = Post.new end
update()
click to toggle source
# File lib/railsbricks/assets/controllers/admin/posts_controller.rb, line 41 def update @post.slug = nil if @post.update(post_params) redirect_to admin_posts_dashboard_path, notice: "Post successfully edited." else flash[:alert] = "The post was not edited." render :edit end end
Private Instance Methods
post_params()
click to toggle source
# File lib/railsbricks/assets/controllers/admin/posts_controller.rb, line 63 def post_params params.require(:post).permit( :title, :content_md, :draft, :updated_at ) end
set_post()
click to toggle source
# File lib/railsbricks/assets/controllers/admin/posts_controller.rb, line 59 def set_post @post = Post.friendly.find(params[:id]) end