Mercurial > zeropaste
changeset 189:b4b7a29b70f6
Initial work for paste deletion.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Sat, 23 Feb 2013 14:01:22 +0900 |
parents | 45ec309a3fa8 |
children | d4682cea8e58 |
files | Gemfile app/controllers/pastes_controller.rb app/views/pastes/_form.html.erb app/views/pastes/show.html.erb config/routes.rb |
diffstat | 5 files changed, 28 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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
--- 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 @@ <div class="field"> <%= f.text_area :paste, :class => 'span12', :rows => 10 %> + + <%= f.text_field :key %> + <span class="help-inline"><%= f.label :key, 'Deletion key' %></span> </div> + <div class="form-actions"> <%= f.submit :class => 'btn btn-primary' %> <%= link_to 'Clear', root_path, :class => 'btn', :id => 'reset_paste' %>
--- 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 @@ </div> </div> +<div class="input-append"> + <%= 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 %> +</div> + <div> <ul class="nav nav-pills"> <li><%= link_to 'Raw', paste_path(@paste, :txt) %></li>
--- a/config/routes.rb Sat Feb 23 13:25:09 2013 +0900 +++ b/config/routes.rb Sat Feb 23 14:01:22 2013 +0900 @@ -1,5 +1,5 @@ Zeropaste::Application.routes.draw do - resources :pastes, :only => [:show, :create], :path => '/' + resources :pastes, :only => [:show, :create, :destroy], :path => '/' post 'pastes' => 'pastes#create', :format => /(json|xml|txt)/ root :to => 'pastes#new' end