Class: Admin::PostsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::PostsController
- Includes:
- ActionControllerMixin
- Defined in:
- app/controllers/admin/posts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
-
#index ⇒ Object
CRUD ===========================================================================================.
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/admin/posts_controller.rb', line 27 def create handle_date_time params, :post, :publication_date @post = @blog.posts.build params[:post] if @post.save @post.publish! if params[:commit] == 'Publish' || params[:post][:state] == 'published' flash[:notice] = 'Successfully created post.' redirect_to @post.path else render :action => 'new' end end |
#destroy ⇒ Object
61 62 63 64 65 |
# File 'app/controllers/admin/posts_controller.rb', line 61 def destroy @post.destroy flash[:notice] = 'Successfully destroyed post.' redirect_to admin_blog_posts_url(@blog) end |
#edit ⇒ Object
40 41 |
# File 'app/controllers/admin/posts_controller.rb', line 40 def edit end |
#index ⇒ Object
CRUD ===========================================================================================
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/admin/posts_controller.rb', line 8 def index params[:labels] = { :slug => 'URL', :state => 'Status', :updated_at => 'Last Modified' } params[:by] ||= 'publication_date' params[:dir] ||= 'desc' @posts = @blog.posts.sort_by{ |p| p[params[:by]] || Time.zone.now } @posts.reverse! if params[:dir] == 'desc' end |
#new ⇒ Object
23 24 25 |
# File 'app/controllers/admin/posts_controller.rb', line 23 def new @post = @blog.posts.build end |
#show ⇒ Object
20 21 |
# File 'app/controllers/admin/posts_controller.rb', line 20 def show end |
#update ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/admin/posts_controller.rb', line 43 def update handle_date_time params, :post, :publication_date if params[:commit] == 'Preview' @post = @blog.posts.new params[:post] render :action => 'preview', :layout => 'application' else if @post.update_attributes params[:post] @post.publish! if params[:commit] == "Publish" @post.unpublish! if params[:commit] == "Save as Draft" flash[:notice] = 'Successfully updated post.' redirect_to @post.path else render :action => 'edit' end end end |