
Untitled
By: a guest on
Jun 4th, 2012 | syntax:
None | size: 1.53 KB | hits: 12 | expires: Never
class PracticesController < ApplicationController
#added for auto complete text (HABTM)
#auto_complete_for :location, :name
#auto_complete_for :employee, :first_name
def index
@practices = Practice.name_like_all(params[:search].to_s.split).ascend_by_name
#@practices = Practice.all
end
def show
@practice = Practice.find(params[:id])
end
def new
@practice = Practice.new
#added
System.find(:all).each do |c|
@practice.implementations.build(:system => c)
end
end
def create
@practice = Practice.new(params[:practice])
#added
params[:implementations].each_value do |k|
@practice.implementations.build(k)
end
if @practice.save
flash[:notice] = "Successfully created practice."
redirect_to @practice
else
render :action => 'new'
end
end
def edit
@practice = Practice.find(params[:id])
end
def update
params[:practice][:employee_ids] ||= []
params[:practice][:location_ids] ||= []
@practice = Practice.find(params[:id])
if @practice.update_attributes(params[:practice])
flash[:notice] = "Successfully updated practice."
redirect_to @practice
else
render :action => 'edit'
end
end
def destroy
@practice = Practice.find(params[:id])
@practice.destroy
flash[:notice] = "Successfully destroyed practice."
redirect_to practices_url
end
end