Ok, here’s projects_controller.rb:
=========================
class ProjectsController < ApplicationController
live_tree(
:project_tree,
:model => :project)
def temp1()
#breakpoint()
end
GET /users/1/projects
GET /users/1/projects.xml
def index
find_user_from_params()
find_parent()
@child_projects = projects_sorted_by_title()
end
GET /users/1/projects/1
GET /users/1/projects/1.xml
def show
find_project_and_parent()
end
GET /users/1/projects/new
def new
find_parent()
@project = Project.new
end
GET /users/1/projects/1;edit
def edit
find_project()
#@user = @project.my_user
#breakpoint()
end
POST /users/1/projects
POST /users/1/projects.xml
def create
find_parent()
@project = Project.new(params[:project])
@user.add_child_to_parent_project(@project, @parent_project)
if @project.save
flash[:notice] = 'Project was successfully created.'
redirect_to project_url(:user_id => @user, :id => @project)
else
render :action => "new"
end
end
PUT /users/1/projects/1
PUT /users/1/projects/1.xml
def update
find_project()
if @project.update_attributes(params[:project])
flash[:notice] = ‘Project was successfully updated.’
redirect_to project_url(:user_id => @user, :id => @project)
else
render :action => “edit”
end
end
DELETE /users/1/projects/1
DELETE /users/1/projects/1.xml
def destroy
find_project_and_parent()
find_user()
@project.my_user.remove_child_project(@project)
@project.destroy()
redirect_to projects_url(:parent_project_id =>
@parent_project, :user_id => @user)
end
private
def find_user_from_params()
an_id = params[:user_id]
redirect_to login_users_url unless an_id
@user = User.find(an_id)
end
def find_project()
@project = Project.find(params[:id])
end
def find_project_and_parent()
find_project()
@parent_project = @project.parent
end
def find_parent()
an_id = params[:parent_project_id]
@parent_project = ((an_id.nil?) ? nil : Project.find(an_id))
end
def projects_sorted_by_title()
@user.children_for_parent_project__sorted_by_title(@parent_project)
end
end
And while we’re at it, here’s application.rb:
=========================
Filters added to this controller apply to all controllers in the
application.
Likewise, all the methods added will be available for all
controllers.
class ApplicationController < ActionController::Base
Pick a unique cookie name to distinguish our session data from
others’
session :session_key => ‘_pjd1_session_id’
end
=========================