# HG changeset patch # User Edho Arief # Date 1361595682 -32400 # Node ID b4b7a29b70f617bfff143e9d3f2af8189cb68697 # Parent 45ec309a3fa85a9f9cfe81a4ba6619e998319375 Initial work for paste deletion. diff -r 45ec309a3fa8 -r b4b7a29b70f6 Gemfile --- a/Gemfile Sat Feb 23 13:25:09 2013 +0900 +++ b/Gemfile Sat Feb 23 14:01:22 2013 +0900 @@ -45,4 +45,5 @@ group :development do gem 'quiet_assets' + gem 'puma' end diff -r 45ec309a3fa8 -r b4b7a29b70f6 app/controllers/pastes_controller.rb --- a/app/controllers/pastes_controller.rb Sat Feb 23 13:25:09 2013 +0900 +++ b/app/controllers/pastes_controller.rb Sat Feb 23 14:01:22 2013 +0900 @@ -21,6 +21,7 @@ # GET / def new @paste = Paste.new + @paste.set_paste_key begin @paste.paste = Paste.find(params[:base]).paste rescue @@ -47,6 +48,9 @@ unless params[:paste][:paste].blank? @paste.paste = params[:paste][:paste] end + if params[:paste][:key] + @paste.key = params[:paste][:key] + end end begin @@ -71,4 +75,15 @@ end end + def destroy + @paste = Paste.find(params[:id].to_i) + if @paste.key == params[:paste][:key] + @paste.destroy + flash[:notice] = "Paste ##{params[:id]} deleted" + redirect_to root_path + else + render :action => :show + end + end + end diff -r 45ec309a3fa8 -r b4b7a29b70f6 app/views/pastes/_form.html.erb --- a/app/views/pastes/_form.html.erb Sat Feb 23 13:25:09 2013 +0900 +++ b/app/views/pastes/_form.html.erb Sat Feb 23 14:01:22 2013 +0900 @@ -13,7 +13,11 @@
<%= f.text_area :paste, :class => 'span12', :rows => 10 %> + + <%= f.text_field :key %> + <%= f.label :key, 'Deletion key' %>
+
<%= f.submit :class => 'btn btn-primary' %> <%= link_to 'Clear', root_path, :class => 'btn', :id => 'reset_paste' %> diff -r 45ec309a3fa8 -r b4b7a29b70f6 app/views/pastes/show.html.erb --- a/app/views/pastes/show.html.erb Sat Feb 23 13:25:09 2013 +0900 +++ b/app/views/pastes/show.html.erb Sat Feb 23 14:01:22 2013 +0900 @@ -36,6 +36,13 @@
+
+ <%= form_for @paste, :method => :delete do |f| %> + <%= f.text_field :key, :value => nil, :placeholder => 'Deletion key' %> + <%= f.submit 'Delete this paste', :class => 'btn btn-danger' %> + <% end %> +
+