Skip to content

Instantly share code, notes, and snippets.

@fayimora
Created January 24, 2012 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fayimora/1672843 to your computer and use it in GitHub Desktop.
Save fayimora/1672843 to your computer and use it in GitHub Desktop.
class ProjectsController < ApplicationController
before_filter :find_project, :only => [:show, :edit, :update, :destroy]
def index
@projects = Project.all
end
def new
@project = Project.new
end
def create
@project = Project.new params[:project]
if @project.save
flash[:notice] = "Project has been created."
redirect_to @project
else
flash[:alert] = "Project has not been created."
render :new
end
end
def show
end
def edit
end
def update
if @project.update_attributes params[:project]
flash[:notice] = "Project has been updated."
redirect_to @project
else
flash[:alert] = "Project has not been updated."
render :edit
end
end
def destroy
@project.destroy
flash[:notice]= "Project has been deleted."
redirect_to projects_path
end
private
def find_project
@project = Project.find params[:id]
rescue ActiveRecord::RecordNotFound
flash[:alert] = "The project you were looking for could not be found"
redirect_to projects_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment