Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. class StepsController < ApplicationController
  2. before_action :require_user
  3.  
  4. def index
  5. case current_step
  6. when nil
  7. redirect_to new_user_path
  8. when 0
  9. redirect_to waiting_for_approval_path
  10. when 1
  11. step_one
  12. end
  13. end
  14.  
  15. def step_one
  16. @header = "bg-index"
  17.  
  18. find_documents_for_step(User::STEP_ONE_DOCUMENTS)
  19. end
  20.  
  21. def upload_documents
  22. if current_user.update_attributes(step_params)
  23. redirect_to waiting_for_approval_path, alert: "Your documents were uploaded"
  24. else
  25. render :index, alert: "Some errors occured"
  26. end
  27. end
  28.  
  29.  
  30. def step_params
  31. #
  32. # TODO:
  33. # 1. check user current_step
  34. hash = Hash.new
  35. User::STEP_ONE_DOCUMENTS.each do |k,v|
  36. str = k.to_s
  37. new_str = str + "_attributes"
  38. sym = new_str.to_sym
  39. hash[sym] = [:file]
  40. end
  41. binding.pry
  42. params.require(:user).permit(hash)
  43. #
  44. # 2. grab documents for this step only (doc_attributes: [:file], doc_attributes2: [:file],)
  45. #case current_step
  46. #when 1
  47. # binding.pry
  48. # params.require(:user).permit(letter_of_representation_attributes: [:file], payment_verification_attributes: [:file])
  49. #when 2
  50. # params.require(:user).permit(foo_attributes: [:file], bar: [:file], baz: [:file])
  51. #end
  52. end
  53.  
  54. def current_step
  55. current_user.step_number
  56. end
  57. def find_documents_for_step(step_documents)
  58. step_documents.each do |st|
  59. # current_user.doc= Document.new unless current_user.doc
  60. unless current_user.send(st)
  61. current_user.send((st.to_s+'=').to_sym, Document.new)
  62. end
  63. end
  64. end
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement