Class: PiccoBlog::PostsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- PiccoBlog::PostsController
- Defined in:
- app/controllers/picco_blog/posts_controller.rb
Instance Method Summary collapse
- #admin_list ⇒ Object
-
#create ⇒ Object
POST /posts.
-
#destroy ⇒ Object
DELETE /posts/1.
-
#edit ⇒ Object
GET /posts/1/edit.
-
#index ⇒ Object
GET /posts.
-
#new ⇒ Object
GET /posts/new.
-
#show ⇒ Object
GET /posts/1.
-
#update ⇒ Object
PATCH/PUT /posts/1.
Instance Method Details
#admin_list ⇒ Object
24 25 26 27 |
# File 'app/controllers/picco_blog/posts_controller.rb', line 24 def admin_list @posts = Post.all.order('id desc') @posts = @posts.page params[:page] end |
#create ⇒ Object
POST /posts
49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/picco_blog/posts_controller.rb', line 49 def create @post = Post.new(post_params) if @post.save redirect_to @post, notice: 'Post was successfully created.' else render :new end end |
#destroy ⇒ Object
DELETE /posts/1
69 70 71 72 |
# File 'app/controllers/picco_blog/posts_controller.rb', line 69 def destroy @post.destroy redirect_to posts_url, notice: 'Post was successfully destroyed.' end |
#edit ⇒ Object
GET /posts/1/edit
45 46 |
# File 'app/controllers/picco_blog/posts_controller.rb', line 45 def edit end |
#index ⇒ Object
GET /posts
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/picco_blog/posts_controller.rb', line 11 def index if params[:tag].present? @posts = Post.visible.tagged_with(params[:tag]).order('id desc') elsif params[:search].present? @posts = Post.visible.search(params[:search]).order("id desc") else @posts = Post.visible.order('id desc') end @posts = @posts.page params[:page] @title = "Blog" end |
#new ⇒ Object
GET /posts/new
40 41 42 |
# File 'app/controllers/picco_blog/posts_controller.rb', line 40 def new @post = Post.new end |
#show ⇒ Object
GET /posts/1
30 31 32 33 34 35 36 37 |
# File 'app/controllers/picco_blog/posts_controller.rb', line 30 def show if request.path != post_path(@post) redirect_to @post, status: :moved_permanently end @title = @post.title @meta_description = @post.excerpt.truncate(300).strip end |
#update ⇒ Object
PATCH/PUT /posts/1
60 61 62 63 64 65 66 |
# File 'app/controllers/picco_blog/posts_controller.rb', line 60 def update if @post.update(post_params) redirect_to @post, notice: 'Post was successfully updated.' else render :edit end end |