Class: Mist::PostsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Mist::PostsController
- Defined in:
- app/controllers/mist/posts_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /posts POST /posts.json.
-
#destroy ⇒ Object
DELETE /posts/1 DELETE /posts/1.json.
-
#edit ⇒ Object
GET /posts/1/edit.
-
#feed ⇒ Object
GET /posts/feed.
-
#index ⇒ Object
GET /posts GET /posts.json.
-
#new ⇒ Object
GET /posts/new GET /posts/new.json.
-
#show ⇒ Object
GET /posts/1 GET /posts/1.json.
-
#update ⇒ Object
PUT /posts/1 PUT /posts/1.json.
Instance Method Details
#create ⇒ Object
POST /posts POST /posts.json
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/mist/posts_controller.rb', line 72 def create redirect_to posts_path and return unless Mist.(:create_post, self) @post = Mist::Post.new(params[:post]) respond_to do |format| if @post.save format.html { redirect_to @post, :notice => 'Post was successfully created.' } format.json { render :json => @post, :status => :created, :location => @post } else format.html { render :action => "new" } format.json { render :json => @post.errors, :status => :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /posts/1 DELETE /posts/1.json
106 107 108 109 110 111 112 113 114 115 |
# File 'app/controllers/mist/posts_controller.rb', line 106 def destroy redirect_to posts_path and return unless Mist.(:destroy_post, self) @post = Mist::Post.find(params[:id]) @post.destroy respond_to do |format| format.html { redirect_to posts_url } format.json { head :ok } end end |
#edit ⇒ Object
GET /posts/1/edit
65 66 67 68 |
# File 'app/controllers/mist/posts_controller.rb', line 65 def edit redirect_to posts_path and return unless Mist.(:update_post, self) @post = Mist::Post.find(params[:id]) end |
#feed ⇒ Object
GET /posts/feed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/mist/posts_controller.rb', line 25 def feed respond_to do |format| format.atom do @title = Mist.title @posts = Mist::Post.all_by_publication_date unless @posts.empty? @updated = @posts.inject(@posts.first.updated_at) do |date, post| date > post.updated_at ? date : post.updated_at end end render :layout => false end format.rss { redirect_to feed_posts_path(:format => :atom), :status => :moved_permanently } end end |
#index ⇒ Object
GET /posts GET /posts.json
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/mist/posts_controller.rb', line 11 def index if Mist. :view_drafts, self @posts = Mist::Post.last(20).reverse else @posts = Mist::Post.recently_published(20) end respond_to do |format| format.html # index.html.erb format.json { render :json => @posts } end end |
#new ⇒ Object
GET /posts/new GET /posts/new.json
54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/mist/posts_controller.rb', line 54 def new redirect_to posts_path and return unless Mist.(:create_post, self) @post = Mist::Post.new respond_to do |format| format.html # new.html.erb format.json { render :json => @post } end end |
#show ⇒ Object
GET /posts/1 GET /posts/1.json
43 44 45 46 47 48 49 50 |
# File 'app/controllers/mist/posts_controller.rb', line 43 def show @post ||= Mist::Post.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render :json => @post } end end |
#update ⇒ Object
PUT /posts/1 PUT /posts/1.json
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/mist/posts_controller.rb', line 89 def update redirect_to posts_path and return unless Mist.(:update_post, self) @post = Mist::Post.find(params[:id]) respond_to do |format| if @post.update_attributes(params[:post]) format.html { redirect_to @post, :notice => 'Post was successfully updated.' } format.json { head :ok } else format.html { render :action => "edit" } format.json { render :json => @post.errors, :status => :unprocessable_entity } end end end |