Ability to delete your asciicast

openid
Marcin Kulik 13 years ago
parent d7ebfac783
commit ebcd3d43a6

@ -1,6 +1,9 @@
class AsciicastsController < ApplicationController class AsciicastsController < ApplicationController
PER_PAGE = 20 PER_PAGE = 20
before_filter :load_resource, :only => [:show, :destroy]
before_filter :ensure_authenticated!, :only => [:destroy]
respond_to :html, :json respond_to :html, :json
def index def index
@ -11,8 +14,28 @@ class AsciicastsController < ApplicationController
end end
def show def show
@asciicast = Asciicast.find(params[:id])
respond_with @asciicast respond_with @asciicast
end end
def destroy
if @asciicast.user == current_user && @asciicast.destroy
redirect_to profile_path(current_user),
:notice => 'Your asciicast was deleted.'
else
if current_user
target = profile_path(current_user)
else
target = root_path
end
redirect_to target,
:alert => "Oops, we couldn't remove this asciicast. Sorry."
end
end
private
def load_resource
@asciicast = Asciicast.find(params[:id])
end
end end

@ -12,6 +12,11 @@
<%= render :partial => 'asciicasts/asciicast', :object => @asciicast %> <%= render :partial => 'asciicasts/asciicast', :object => @asciicast %>
<% if @asciicast.user == current_user %>
<%= link_to 'Delete this asciicast', asciicast_path(@asciicast),
:method => :delete, :confirm => 'U SHURE?', :class => 'delete-link' %>
<% end %>
<div class="comments-container"> <div class="comments-container">
<h2>Comments</h2> <h2>Comments</h2>
@ -40,5 +45,5 @@
comments.fetch(); comments.fetch();
new AsciiIo.Views.CommentsIndex({ collection: comments }); new AsciiIo.Views.CommentsIndex({ collection: comments });
}) });
</script> </script>

Loading…
Cancel
Save