Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1.  
  2.  
  3. Old ConfigTemplateController#update:
  4.  
  5.  
  6. def update
  7. @config_template = ConfigTemplate.find(params[:id])
  8. respond_to do |format|
  9. if @config_template.update_attributes(params[:config_template])
  10. format.html do
  11. notice "Successfully updated config template."
  12. redirect_to config_templates_url
  13. end
  14. format.json {render :json => @config_template, :status => :ok}
  15. else
  16. format.html {render :action => 'edit'}
  17. format.json {render :json => @config_template.errors, :status => :unprocessable_entity}
  18. end
  19. end
  20. end
  21.  
  22.  
  23. New ConfigTemplateController#update:
  24.  
  25. def update
  26. @config_template = ConfigTemplate.find(params[:id])
  27. if @config_template.update_attributes(params[:config_template])
  28. process_success @config_template, "Successfully updated config template.", config_templates_url
  29. else
  30. process_error @config_template, :render =>"edit"
  31. end
  32. end
  33.  
  34.  
  35.  
  36. New methods in application_controller:
  37.  
  38.  
  39. def process_success object, success_msg, success_redirect, json_code = :ok
  40. respond_to do |format|
  41. format.html do
  42. notice success_msg
  43. redirect_to success_redirect
  44. end
  45. format.json { render :json => object, :status => json_code}
  46. end
  47. end
  48.  
  49. def process_error object, hash
  50. hash[:json_code] ||= :unprocessable_entity
  51. respond_to do |format|
  52. format.html do
  53. error hash[:error_msg] if hash[:error_msg]
  54. render :action => hash[:render] if hash[:render]
  55. redirect_to hash[:redirect] if hash[:redirect]
  56. end
  57. format.json { render :json => object.errors, :status => hash[:json_code]}
  58. end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement