Adding resource category edit abilities
This commit is contained in:
46
app/controllers/resource_categories_controller.rb
Executable file
46
app/controllers/resource_categories_controller.rb
Executable file
@@ -0,0 +1,46 @@
|
||||
class ResourceCategoriesController < ApplicationController
|
||||
load_and_authorize_resource
|
||||
layout 'resources'
|
||||
|
||||
def create
|
||||
authorize! :create, @resource_category
|
||||
|
||||
respond_to do |format|
|
||||
if @resource_category.save
|
||||
format.html { redirect_to resource_categories_path, :notice => "Category was successfully created." }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
format.json { render :json => @resource_category.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
authorize! :update, @resource_category
|
||||
|
||||
respond_to do |format|
|
||||
if @resource_category.update_attributes(params[:resource_category])
|
||||
format.html { redirect_to resource_categories_path, :notice => "Category was successfully updated." }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render :action => "edit" }
|
||||
format.json { render :json => @resource_category.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
||||
respond_to do |format|
|
||||
if @resource_category.destroy
|
||||
format.html { redirect_to resource_categories_path, :notice => "Category was deleted." }
|
||||
format.json { head :ok }
|
||||
else
|
||||
format.html { redirect_to resource_categories_path, :notice => "Category could not be deleted. #{@resource_category.errors.full_messages.first}." }
|
||||
format.json { render :json => @resource_category.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,6 +1,7 @@
|
||||
class ResourcesController < ApplicationController
|
||||
load_and_authorize_resource
|
||||
before_filter :load_users
|
||||
layout 'resources'
|
||||
|
||||
def index
|
||||
@featured_resource = @resources.where("picture_file_name IS NOT NULL").sample
|
||||
@@ -58,4 +59,5 @@ class ResourcesController < ApplicationController
|
||||
@users = [current_user]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user