Class: Blog::PostsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Blog::PostsController
- Defined in:
- app/controllers/blog/posts_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /blog/posts.
-
#destroy ⇒ Object
DELETE /blog/posts/1.
-
#edit ⇒ Object
GET /blog/posts/1/edit.
-
#index ⇒ Object
GET /blog/posts.
- #list ⇒ Object
-
#new ⇒ Object
GET /blog/posts/new.
-
#show ⇒ Object
GET /blog/posts/1.
- #show_list ⇒ Object
-
#update ⇒ Object
PATCH/PUT /blog/posts/1.
Instance Method Details
#create ⇒ Object
POST /blog/posts
42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/blog/posts_controller.rb', line 42 def create :create, @blog_post @blog_post = Post.new(blog_post_params) if @blog_post.save redirect_to @blog_post, notice: 'Post was successfully created.' else render :new end end |
#destroy ⇒ Object
DELETE /blog/posts/1
63 64 65 66 |
# File 'app/controllers/blog/posts_controller.rb', line 63 def destroy @blog_post.destroy redirect_to blog_posts_url, notice: 'Post was successfully destroyed.' end |
#edit ⇒ Object
GET /blog/posts/1/edit
38 39 |
# File 'app/controllers/blog/posts_controller.rb', line 38 def edit end |
#index ⇒ Object
GET /blog/posts
7 8 9 10 11 12 13 |
# File 'app/controllers/blog/posts_controller.rb', line 7 def index if params[:tag] @blog_posts = Post.tagged_with(params[:tag]).page params[:page] else @blog_posts = Post.all.page params[:page] end end |
#list ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'app/controllers/blog/posts_controller.rb', line 15 def list if params[:tag] @blog_posts = Post.tagged_with(params[:tag]).page params[:page] else @blog_posts = Post.where('? >= published_at and draft = ?', DateTime.now, false).includes(:user).page params[:page] end end |
#new ⇒ Object
GET /blog/posts/new
33 34 35 |
# File 'app/controllers/blog/posts_controller.rb', line 33 def new @blog_post = Post.new end |
#show ⇒ Object
GET /blog/posts/1
25 26 |
# File 'app/controllers/blog/posts_controller.rb', line 25 def show end |
#show_list ⇒ Object
28 29 30 |
# File 'app/controllers/blog/posts_controller.rb', line 28 def show_list @blog_post.increment!(:access_count) end |
#update ⇒ Object
PATCH/PUT /blog/posts/1
54 55 56 57 58 59 60 |
# File 'app/controllers/blog/posts_controller.rb', line 54 def update if @blog_post.update(blog_post_params) redirect_to @blog_post, notice: 'Post was successfully updated.' else render :edit end end |