Skip to content

Instantly share code, notes, and snippets.

@rangalo
Created July 29, 2010 16:34
Show Gist options
  • Select an option

  • Save rangalo/498600 to your computer and use it in GitHub Desktop.

Select an option

Save rangalo/498600 to your computer and use it in GitHub Desktop.
class ProjectsController < ApplicationController
# GET /projects
# GET /projects.xml
def index
@title = "Projekte"
@projects = Project.all
respond_to do |format|
format.html # index.html.erb
# format.xml { render :partial => 'grid_data.xml.builder', :layout => false }
end
end
# GET /projects/new
# GET /projects/new.xml
def new
@title = "Neues Projekt"
@project = Project.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @project }
end
end
# GET /projects/1
# GET /projects/1.xml
def show
@project = Project.find(params[:id])
@title = "#{@project.name}"
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @project }
end
end
# GET /projects/1/edit
def edit
@title = "Projekt editieren"
@project = Project.find(params[:id])
end
# POST /projects
# POST /projects.xml
def create
@project = Project.new(params[:project])
respond_to do |format|
if @project.save
flash[:notice] = 'Projekt wurde erfolgreich erstellt.'
format.html { redirect_to(@project) }
format.xml { render :xml => @project, :status => :created, :location => @project }
else
format.html { render :action => "new" }
format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
end
end
end
# PUT /candidates/1
# PUT /candidates/1.xml
def update
@project = Project.find(params[:id])
respond_to do |format|
if @project.update_attributes(params[:project])
flash[:notice] = 'Projekt wurde erfolgreich gespeichert.'
format.html { redirect_to(@project) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
end
end
end
def add_candidates
@project = Project.find_by_id(params[:project_id])
if params[:candidate_ids].nil?
@candidates = []
else
@candidates = params[:candidate_ids]
end
@candidates.each do |candidate|
@project.add_candidate!(candidate)
end
redirect_to candidates_path
end
edn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment