Created
January 24, 2012 21:31
-
-
Save fayimora/1672843 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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