Class: Proclaim::PostsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Proclaim::PostsController
- Defined in:
- app/controllers/proclaim/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.
-
#show ⇒ Object
GET /posts/1.
-
#update ⇒ Object
PATCH/PUT /posts/1.
Instance Method Details
#create ⇒ Object
POST /posts
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/proclaim/posts_controller.rb', line 45 def create @post = Post.new(post_params) @post. = if params[:publish] == "true" @post.publish end @post if @post.save redirect_to @post, notice: 'Post was successfully created.' else render :new end end |
#destroy ⇒ Object
DELETE /posts/1
81 82 83 84 85 86 |
# File 'app/controllers/proclaim/posts_controller.rb', line 81 def destroy @post @post.destroy redirect_to posts_url, notice: 'Post was successfully destroyed.' end |
#edit ⇒ Object
GET /posts/1/edit
40 41 42 |
# File 'app/controllers/proclaim/posts_controller.rb', line 40 def edit @post end |
#index ⇒ Object
GET /posts
11 12 13 14 |
# File 'app/controllers/proclaim/posts_controller.rb', line 11 def index @posts = policy_scope(Post).order(published_at: :desc, updated_at: :desc) Post end |
#new ⇒ Object
GET /posts/new
34 35 36 37 |
# File 'app/controllers/proclaim/posts_controller.rb', line 34 def new @post = Post.new(author: ) @post end |
#show ⇒ Object
GET /posts/1
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/proclaim/posts_controller.rb', line 17 def show @post # Don't track traffic if it's a logged-in user unless @post.punch(request) end # If an old id or a numeric id was used to find the record, then # the request path will not match the post_path, and we should do # a 301 redirect that uses the current friendly id. if request.path != post_path(@post) return redirect_to @post, status: :moved_permanently end end |
#update ⇒ Object
PATCH/PUT /posts/1
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/proclaim/posts_controller.rb', line 63 def update @post.assign_attributes(post_params) if (params[:publish] == "true") and not @post.published? @post.publish @post. = # Reassign author when it's published end @post if @post.save redirect_to @post, notice: 'Post was successfully updated.' else render :edit end end |