Created
September 9, 2012 03:46
-
-
Save nfriend21/3682449 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
before_filter :authorize | |
def index | |
@tasks = Task.all | |
@users = User.all | |
end | |
def new | |
@task = Task.new | |
current_user.tasks.company_id = (params[:task][:company_id]) | |
end | |
def create | |
@task = current_user.tasks.create(params[:task]) | |
#@task.company.build(params[:company]) | |
if @task.save | |
#@task.company = @company | |
flash[:success] = "Your task has been created!" | |
redirect_to companies_path | |
else | |
render 'new' | |
end | |
end | |
def show | |
@task = Task.find(params[:id]) | |
respond_to do |format| | |
format.html # show.html.erb | |
format.json { render json: @task } | |
end | |
end | |
def edit | |
@task = Task.find(params[:id]) | |
session[:return_to] = request.referer #this stores the requesting url (where you clicked "edit") in a session hash, which is available across multiple requests. Now you can use it in the Update action. | |
end | |
def update | |
@task = Task.find(params[:id]) | |
if @task.update_attributes params[:task] | |
redirect_to session[:return_to] #this redirects to the requesting URL, as per the Edit action where this was initially stored. | |
flash[:success] = "Task was successfully updated." | |
else | |
redirect_to :back | |
end | |
end | |
def destroy | |
@task = Task.find(params[:id]) | |
@user = @task.user_id | |
@task.destroy | |
flash[:success] = "The task has been deleted." | |
redirect_to user_path(@user) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment