Split out updating a trace into an update action

This commit is contained in:
Andy Allan 2018-08-29 17:31:12 +08:00
parent db39876dd6
commit b745126b6e
6 changed files with 39 additions and 49 deletions

View file

@ -175,13 +175,24 @@ class TracesController < ApplicationController
head :forbidden
else
@title = t ".title", :name => @trace.name
end
rescue ActiveRecord::RecordNotFound
head :not_found
end
if request.post? && params[:trace]
@trace.description = params[:trace][:description]
@trace.tagstring = params[:trace][:tagstring]
@trace.visibility = params[:trace][:visibility]
redirect_to :action => "view", :display_name => current_user.display_name if @trace.save
end
def update
@trace = Trace.find(params[:id])
if !@trace.visible?
head :not_found
elsif current_user.nil? || @trace.user != current_user
head :forbidden
elsif @trace.update(trace_params)
flash[:notice] = t ".updated"
redirect_to :action => "view", :display_name => current_user.display_name
else
@title = t ".title", :name => @trace.name
render :action => "edit"
end
rescue ActiveRecord::RecordNotFound
head :not_found
@ -413,4 +424,8 @@ class TracesController < ApplicationController
"public"
end
end
def trace_params
params.require(:trace).permit(:description, :tagstring, :visibility)
end
end