From 58926cf3ab32023bcb031541ed702dd615e2967b Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Sun, 9 Feb 2014 02:08:08 -0700 Subject: [PATCH] Updating resources --- app/controllers/resources_controller.rb | 9 ++++ app/models/resource.rb | 9 +++- app/views/devise/registrations/edit.html.erb | 2 +- app/views/resources/_resource.html.erb | 9 ++++ app/views/resources/index.html.erb | 51 ++++++++----------- .../20140209080523_add_user_id_to_resource.rb | 5 ++ db/schema.rb | 3 +- 7 files changed, 55 insertions(+), 33 deletions(-) create mode 100644 app/views/resources/_resource.html.erb create mode 100644 db/migrate/20140209080523_add_user_id_to_resource.rb 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 @@