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

Untitled

By: a guest on Aug 5th, 2012  |  syntax: None  |  size: 1.26 KB  |  hits: 11  |  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.  33   respond_to :json¬
  2.  34   def update¬
  3.  35     @resume = current_user.resumes.find params[:id]¬                                
  4.  36 ¬
  5.  37     key = params[:model]¬
  6.  38     hash_id = params[key]['hash_id']¬
  7.  39     params[key][:start_date] = Time.utc params[key][:start_date][:year], \¬
  8.  40       params[key][:start_date][:month] if params[key].has_key? :start_date¬
  9.  41     params[key][:end_date] = Time.utc params[key][:end_date][:year], \¬
  10.  42       params[key][:end_date][:month] if params[key].has_key? :end_date¬
  11.  43 ¬
  12.  44     logger.debug params¬
  13.  45 ¬
  14.  46     @section = @resume.send(key.pluralize).find(:all, :conditions => { :hash_id => h    ash_id })¬
  15.  47     logger.debug @section¬
  16.  48 ¬
  17.  49     if @section and not @section.empty?¬
  18.  50       logger.debug "update_attributes"¬
  19.  51       @section.first.update_attributes params[key]¬
  20.  52     else¬
  21.  53       logger.debug "create new record"¬
  22.  54       @section = @resume.send(key.pluralize).new(params[key])¬
  23.  55       logger.debug @section¬
  24.  56       if @section.save¬
  25.  57         logger.debug 'created successfully'¬
  26.  58         render :json => @section¬
  27.  59       else¬
  28.  60         logger.debug 'created UNsuccessfully'¬
  29.  61         render 'edit'¬
  30.  62       end¬
  31.  63     end¬
  32.  64 ¬
  33.  65   end¬