Editing of title/description

openid
Marcin Kulik 13 years ago
parent e28aa23e68
commit 8a9fc6fa89

@ -1,8 +1,9 @@
class AsciicastsController < ApplicationController
PER_PAGE = 20
before_filter :load_resource, :only => [:show, :destroy]
before_filter :ensure_authenticated!, :only => [:destroy]
before_filter :load_resource, :only => [:show, :edit, :update, :destroy]
before_filter :ensure_authenticated!, :only => [:edit, :update, :destroy]
before_filter :ensure_owner!, :only => [:edit, :update, :destroy]
respond_to :html, :json
@ -17,18 +18,21 @@ class AsciicastsController < ApplicationController
respond_with @asciicast
end
def edit
end
def update
@asciicast.update_attributes(params[:asciicast])
redirect_to asciicast_path(@asciicast),
:notice => 'Your asciicast was updated.'
end
def destroy
if @asciicast.user == current_user && @asciicast.destroy
if @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,
redirect_to asciicast_path(@asciicast),
:alert => "Oops, we couldn't remove this asciicast. Sorry."
end
end
@ -38,4 +42,10 @@ class AsciicastsController < ApplicationController
def load_resource
@asciicast = Asciicast.find(params[:id])
end
def ensure_owner!
if @asciicast.user != current_user
redirect_to asciicast_path(@asciicast), :alert => "You can't do that."
end
end
end

@ -14,7 +14,8 @@ class Asciicast < ActiveRecord::Base
before_create :assign_user, :unless => :user
attr_accessible :meta, :stdout, :stdout_timing, :stdin, :stdin_timing
attr_accessible :meta, :stdout, :stdout_timing, :stdin, :stdin_timing,
:title, :description
def self.assign_user(user_token, user)
where(:user_id => nil, :user_token => user_token).

@ -0,0 +1,28 @@
<%= form_for @asciicast, :html => { :class => 'form-horizontal' } do |f| %>
<fieldset>
<legend><%= controller.action_name.capitalize %> asciicast</legend>
<div class="control-group">
<%= f.label :title, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :title, :class => 'text_field span6' %>
</div>
</div>
<div class="control-group">
<%= f.label :description, :class => 'control-label' %>
<div class="controls">
<%= f.text_area :description, :class => 'text_area span6' %>
</div>
<div class="controls">
Parsed with <a href="http://github.github.com/github-flavored-markdown/"
target="_blank">GitHub Flavored Markdown</a>
</div>
</div>
<div class="form-actions">
<%= f.submit 'Update asciicast', :class => 'btn btn-primary' %>
<%= link_to 'Cancel', asciicast_path, :class => 'btn' %>
</div>
</fieldset>
<% end %>

@ -0,0 +1 @@
<%= render :partial => 'form' %>
Loading…
Cancel
Save