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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/proclaim/posts_controller.rb', line 39 def create @post = Post.new(post_params) @post. = if params[:publish] == "true" @post.publish end @post if @post.valid? # Save and rewrite each image in Carrierwave's cache @post.body = saved_and_rewrite_cached_images(@post.body) @post.save redirect_to @post, notice: 'Post was successfully created.' else render :new end end |
#destroy ⇒ Object
DELETE /posts/1
85 86 87 88 89 90 |
# File 'app/controllers/proclaim/posts_controller.rb', line 85 def destroy @post @post.destroy redirect_to posts_url, notice: 'Post was successfully destroyed.' end |
#edit ⇒ Object
GET /posts/1/edit
34 35 36 |
# File 'app/controllers/proclaim/posts_controller.rb', line 34 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
28 29 30 31 |
# File 'app/controllers/proclaim/posts_controller.rb', line 28 def new @post = Post.new(author: ) @post end |
#show ⇒ Object
GET /posts/1
17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/proclaim/posts_controller.rb', line 17 def show begin @post rescue Pundit::NotAuthorizedError # Don't leak that this resource actually exists. Turn the # "permission denied" into a "not found" raise ActiveRecord::RecordNotFound end end |
#update ⇒ Object
PATCH/PUT /posts/1
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/proclaim/posts_controller.rb', line 62 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.valid? # Save and rewrite each image in Carrierwave's cache @post.body = saved_and_rewrite_cached_images(@post.body) @post.save redirect_to @post, notice: 'Post was successfully updated.' else render :edit end end |