diff --git a/app/controllers/resources_controller.rb b/app/controllers/resources_controller.rb index ad75e95..90c6d40 100755 --- a/app/controllers/resources_controller.rb +++ b/app/controllers/resources_controller.rb @@ -1,4 +1,13 @@ class ResourcesController < ApplicationController load_and_authorize_resource before_filter :authenticate_user! + + def destroy + @resource.destroy + + respond_to do |format| + format.html { redirect_to(request.env["HTTP_REFERER"]) } + format.json { head :ok } + end + end end diff --git a/app/models/resource.rb b/app/models/resource.rb index d1d1646..98e5d97 100755 --- a/app/models/resource.rb +++ b/app/models/resource.rb @@ -1,7 +1,8 @@ class Resource < ActiveRecord::Base - belongs_to :owner, :class_name => "ToolshareUser" + belongs_to :owner, :class_name => "ToolshareUser" #TODO: remove owner + belongs_to :user belongs_to :category, :class_name => "ResourceCategory" - has_attached_file :picture, + has_attached_file :picture, #TODO: move to local storage :styles => { :medium => "300x300>", :thumb => "100x100>", :tiny => "50x50>"}, @@ -9,4 +10,8 @@ class Resource < ActiveRecord::Base :s3_credentials => Rails.root.join('config', 's3.yml'), :path => ":attachment/:id/:style.:extension", :bucket => 'Toolshare' + + def category_name + self.category.name if self.category + end end diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 33de186..51cd7c4 100755 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -4,7 +4,7 @@
- | <%= sort_link 'Owner', :owner_id %> | -<%= sort_link 'Category', :category_id %> | -<%= sort_link 'Name', :name %> | -<%= sort_link 'Serial', :serial %> | -<%= sort_link 'Status/Location', :status %> | -||
---|---|---|---|---|---|---|---|
<%= supercategory %> | |||||||
- <%= link_to image_tag(resource.picture.url(:tiny)), resource.picture.url, :popup => ['index_image_preview', 'height=300,width=400'] if resource.picture? %> - | -- <%=h resource.owner.name if resource.owner %> - | <%=h resource.category.name unless resource.category.nil? %> | -<%=h resource.name %> | -<%=h resource.serial %> | -<%=h resource.status %> | -<%= link_to 'Edit', edit_resource_path(resource) if can? :update, resource %> | -<%= link_to 'Destroy', resource, :confirm => 'Are you sure you want to delete this?', :method => :delete if can? :destroy, resource %> | -