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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/mist/posts_controller.rb', line 68 def create redirect_to posts_path and return unless Mist.(:create_post, self) coerce_date(params[:post], 'published_at') @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
104 105 106 107 108 109 110 111 112 113 |
# File 'app/controllers/mist/posts_controller.rb', line 104 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
61 62 63 64 |
# File 'app/controllers/mist/posts_controller.rb', line 61 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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/mist/posts_controller.rb', line 21 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 |
# File 'app/controllers/mist/posts_controller.rb', line 11 def index @posts = Mist::Post.recently_published(20, Mist.(:view_drafts, self)) 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
50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/mist/posts_controller.rb', line 50 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
39 40 41 42 43 44 45 46 |
# File 'app/controllers/mist/posts_controller.rb', line 39 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
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/controllers/mist/posts_controller.rb', line 86 def update redirect_to posts_path and return unless Mist.(:update_post, self) @post = Mist::Post.find(params[:id]) respond_to do |format| coerce_date(params[:post], 'published_at') 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 |