Geplantes Gitlab Update: Donnerstag, Morgens vor 9 Uhr

Commit 936667cb authored by simon's avatar simon
Browse files

Refactor posts update method

Begone, code-smells!
parent 28058328
......@@ -48,26 +48,8 @@ class PostsController < ApplicationController
if @post.content_image.attached? || @post.content_file.attached?
@post.content_image.attach(post_params[:content_image]) unless post_params[:content_image].nil?
@post.content_file.attach(post_params[:content_file]) unless post_params[:content_file].nil?
respond_to do |format|
if @post.update(post_params.except(:content_image, :content_file))
format.html { redirect_to @post, notice: 'Post was successfully updated.' }
format.json { render :show, status: :ok, location: @post }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
else
respond_to do |format|
if @post.update(post_params)
format.html { redirect_to @post, notice: 'Post was successfully updated.' }
format.json { render :show, status: :ok, location: @post }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end
response_update
end
# DELETE /posts/1
......@@ -100,6 +82,18 @@ class PostsController < ApplicationController
private
def response_update
respond_to do |format|
if @post.update(post_params)
format.html { redirect_to @post, notice: 'Post was successfully updated.' }
format.json { render :show, status: :ok, location: @post }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end
# Use callbacks to share common setup or constraints between actions.
def set_post
@post = Post.find(params[:id])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment