Skip to content

Instantly share code, notes, and snippets.

@Undistraction
Created September 20, 2013 13:08
Show Gist options
  • Save Undistraction/6637232 to your computer and use it in GitHub Desktop.
Save Undistraction/6637232 to your computer and use it in GitHub Desktop.
class ResourceController < ApplicationController
include ResourcesHelper
respond_to :html
before_filter :find_resource, only: [:show, :edit, :update, :destroy]
before_filter :add_crumb_auto, only: [:new, :show, :edit, :index]
def initialize
super
@hide_edit_button = false
@hide_show_button = false
end
def index
if params[:search]
@resources = @resource_class.search(params[:search])
else
@resources = @resource_class.all
end
respond_with @resources
end
def show
respond_with @resource
end
def new
@resource = @resource_class.new
respond_with @resource
end
def edit
respond_with @resource
end
def create
@resource = @resource_class.new(params[resource_symbol])
flash[:notice] = "#{@resource_class.name} was successfully created" if @resource.save
respond_with @resource
end
def update
flash[:notice] = "#{@resource_class.name} was successfully updated" if @resource.update_attributes(params[resource_symbol])
respond_with @resource
end
def destroy
@resource.destroy
redirect_to(resources_path, notice: "Deleted Archive Resource")
end
protected
def find_resource
@resource = @resource_class.find(params[:id])
end
def resource_symbol
@resource_class.name.underscore.to_sym
end
end
class ArchiveResourcesController < ResourceController
def initialize
super
@resource_class = ArchiveResource
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment