comparison app/controllers/pastes_controller.rb @ 265:6cca1ab53337

Infinitely better error messages and notice.
author edogawaconan <me@myconan.net>
date Wed, 16 Oct 2013 02:56:30 +0900
parents 16251b94eb6c
children 200488650a86
comparison
equal deleted inserted replaced
264:fa4a1ba990ae 265:6cca1ab53337
46 if @paste.save 46 if @paste.save
47 @fresh = true 47 @fresh = true
48 format.html { redirect_to @paste, :notice => 'Paste was successfully created.' } 48 format.html { redirect_to @paste, :notice => 'Paste was successfully created.' }
49 format.json { render :json => @paste, :status => :created, :location => @paste } 49 format.json { render :json => @paste, :status => :created, :location => @paste }
50 else 50 else
51 flash[:alert] = @paste.errors.full_messages.to_sentence
51 format.html { render :action => "new" } 52 format.html { render :action => "new" }
52 format.json { render :json => @paste.errors, :status => :unprocessable_entity } 53 format.json { render :json => @paste.errors, :status => :unprocessable_entity }
53 end 54 end
54 format.txt 55 format.txt
55 end 56 end
63 end 64 end
64 end 65 end
65 66
66 def destroy 67 def destroy
67 @paste = Paste.safe_find(params[:id]) 68 @paste = Paste.safe_find(params[:id])
68 if @paste.key == params[:paste][:key] 69 if @paste.safe_destroy(params[:paste][:key])
69 @paste.destroy
70 expire_page :controller => 'pastes', :action => 'show', :id => @paste.id 70 expire_page :controller => 'pastes', :action => 'show', :id => @paste.id
71 flash[:notice] = "Paste ##{params[:id]} deleted" 71 redirect_to root_path, :notice => "Paste ##{params[:id]} deleted"
72 redirect_to root_path
73 else 72 else
74 flash[:error] = 'Incorrect deletion key' 73 flash[:alert] = @paste.errors.full_messages.to_sentence
75 render :action => :show 74 render :show
76 end 75 end
77 end 76 end
78 77
79 private 78 private
80 def paste_params 79 def paste_params