Class: Admin::PostsController
- Inherits:
-
BaseController
- Object
- BaseController
- Admin::PostsController
- Defined in:
- lib/railsbricks/assets/controllers/admin/posts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #dashboard ⇒ Object
- #destroy ⇒ Object
- #drafts ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# 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 ⇒ Object
10 11 12 13 |
# 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 ⇒ Object
51 52 53 54 |
# 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 ⇒ Object
19 20 21 |
# File 'lib/railsbricks/assets/controllers/admin/posts_controller.rb', line 19 def drafts @posts = Post.drafted.page(params[:page]).per(50) end |
#edit ⇒ Object
38 39 |
# File 'lib/railsbricks/assets/controllers/admin/posts_controller.rb', line 38 def edit end |
#index ⇒ Object
15 16 17 |
# File 'lib/railsbricks/assets/controllers/admin/posts_controller.rb', line 15 def index @posts = Post.published.page(params[:page]).per(50) end |
#new ⇒ Object
23 24 25 |
# File 'lib/railsbricks/assets/controllers/admin/posts_controller.rb', line 23 def new @post = Post.new end |
#update ⇒ Object
41 42 43 44 45 46 47 48 49 |
# 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 |