Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 4th, 2012  |  syntax: None  |  size: 1.53 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class PracticesController < ApplicationController
  2.  
  3.   #added for auto complete text (HABTM)
  4.   #auto_complete_for :location, :name
  5.   #auto_complete_for :employee, :first_name
  6.  
  7.   def index
  8.     @practices = Practice.name_like_all(params[:search].to_s.split).ascend_by_name
  9.     #@practices = Practice.all
  10.   end
  11.  
  12.   def show
  13.     @practice = Practice.find(params[:id])
  14.   end
  15.  
  16.   def new
  17.     @practice = Practice.new
  18.    
  19.  #added
  20.     System.find(:all).each do |c|
  21.       @practice.implementations.build(:system => c)
  22.     end
  23.    
  24.  
  25.   end
  26.  
  27.   def create
  28.     @practice = Practice.new(params[:practice])  
  29.    
  30.  #added
  31.     params[:implementations].each_value do |k|
  32.         @practice.implementations.build(k)
  33.       end
  34.      
  35.  
  36.     if @practice.save
  37.       flash[:notice] = "Successfully created practice."
  38.       redirect_to @practice
  39.     else
  40.       render :action => 'new'
  41.     end
  42.   end
  43.  
  44.   def edit
  45.     @practice = Practice.find(params[:id])
  46.   end
  47.  
  48.   def update
  49.    
  50.     params[:practice][:employee_ids] ||= []
  51.     params[:practice][:location_ids] ||= []  
  52.    
  53.    
  54.      
  55.    
  56.     @practice = Practice.find(params[:id])
  57.     if @practice.update_attributes(params[:practice])
  58.       flash[:notice] = "Successfully updated practice."
  59.       redirect_to @practice
  60.     else
  61.       render :action => 'edit'
  62.     end
  63.   end
  64.  
  65.   def destroy
  66.     @practice = Practice.find(params[:id])
  67.     @practice.destroy
  68.     flash[:notice] = "Successfully destroyed practice."
  69.     redirect_to practices_url
  70.   end
  71. end