Class: Homeland::Press::PostsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Homeland::Press::PostsController
- Defined in:
- app/controllers/homeland/press/posts_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /posts.
-
#destroy ⇒ Object
DELETE /posts/1.
-
#edit ⇒ Object
GET /posts/1/edit.
-
#index ⇒ Object
GET /posts.
-
#new ⇒ Object
GET /posts/new.
- #preview ⇒ Object
- #publish ⇒ Object
-
#show ⇒ Object
GET /posts/1.
- #upcoming ⇒ Object
-
#update ⇒ Object
PATCH/PUT /posts/1.
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
POST /posts
37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/homeland/press/posts_controller.rb', line 37 def create :create, Post @post = Post.new(post_params) @post.user_id = current_user.id if @post.save redirect_to @post, notice: '文章提交成功,需要等待管理员审核。' else render :new end end |
#destroy ⇒ Object
DELETE /posts/1
66 67 68 69 70 |
# File 'app/controllers/homeland/press/posts_controller.rb', line 66 def destroy :destroy, @post @post.destroy redirect_to posts_url, notice: '文章删除成功。' end |
#edit ⇒ Object
GET /posts/1/edit
32 33 34 |
# File 'app/controllers/homeland/press/posts_controller.rb', line 32 def edit :update, @post end |
#index ⇒ Object
GET /posts
7 8 9 |
# File 'app/controllers/homeland/press/posts_controller.rb', line 7 def index @posts = Post.includes(:user).published.order('published_at desc, id desc').page(params[:page]).per(10) end |
#new ⇒ Object
GET /posts/new
26 27 28 29 |
# File 'app/controllers/homeland/press/posts_controller.rb', line 26 def new :create, Post @post = Post.new end |
#preview ⇒ Object
20 21 22 23 |
# File 'app/controllers/homeland/press/posts_controller.rb', line 20 def preview out = Homeland::Markdown.call(params[:body]) render plain: out end |
#publish ⇒ Object
59 60 61 62 63 |
# File 'app/controllers/homeland/press/posts_controller.rb', line 59 def publish :publish, @post @post.published! redirect_to posts_path, notice: "文章审核成功。" end |
#show ⇒ Object
GET /posts/1
16 17 18 |
# File 'app/controllers/homeland/press/posts_controller.rb', line 16 def show @post.hits.incr(1) end |
#upcoming ⇒ Object
11 12 13 |
# File 'app/controllers/homeland/press/posts_controller.rb', line 11 def upcoming @posts = Post.includes(:user).upcoming.order('id desc').page(params[:page]).per(10) end |
#update ⇒ Object
PATCH/PUT /posts/1
50 51 52 53 54 55 56 57 |
# File 'app/controllers/homeland/press/posts_controller.rb', line 50 def update :update, @post if @post.update(post_params) redirect_to @post, notice: '文章更新成功。' else render :edit end end |