before_action :check_api_writable, :only => [:api_create, :api_update, :api_delete]
before_action :require_allow_read_gpx, :only => [:api_read, :api_data]
before_action :require_allow_write_gpx, :only => [:api_create, :api_update, :api_delete]
- before_action :offline_warning, :only => [:mine, :view]
+ before_action :offline_warning, :only => [:mine, :show]
before_action :offline_redirect, :only => [:new, :create, :edit, :delete, :data, :api_create, :api_delete, :api_data]
around_action :api_call_handle_error, :only => [:api_create, :api_read, :api_update, :api_delete, :api_data]
redirect_to :action => :list, :display_name => current_user.display_name
end
- def view
+ def show
@trace = Trace.find(params[:id])
if @trace && @trace.visible? &&
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 => "show", :display_name => current_user.display_name
+ else
+ @title = t ".title", :name => @trace.name
+ render :action => "edit"
end
rescue ActiveRecord::RecordNotFound
head :not_found
"public"
end
end
+
+ def trace_params
+ params.require(:trace).permit(:description, :tagstring, :visibility)
+ end
end