Created
December 24, 2009 05:37
-
-
Save metasoarous/263035 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 TasksController < ApplicationController | |
def create | |
@task = Task.new(params[:task]) | |
respond_to do |format| | |
# If all is well, clear out the new_task store and redirect to the project | |
if @task.save | |
session[:new_task] = nil | |
flash[:notice] = 'Task added successfully' | |
format.html { redirect_to @task.project } | |
# If something goes south, save the task that is being worked on | |
else | |
session[:new_task] = @task | |
format.html { redirect_to @task.project } | |
end | |
end | |
end | |
# other actions... | |
end | |
class ProjectsController < ApplicationController | |
def show | |
@project = Project.find(params[:id]) | |
# don't want to accidentally display the task that is being worked on | |
@old_shifts = @project.tasks.delete_if {|s| s.new_record?} | |
# If we are already working on a task in the store, use that, otherwise instantiate a new one | |
@new_task = session[:new_task] || Task.new(:project_id => @project.id) | |
respond_to do |format| | |
format.html | |
end | |
end | |
# other actions... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment