Guest User

Untitled

a guest
Feb 21st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. ## model
  2. class Organization < ActiveRecord::Base
  3. before_create :create_access_key
  4. before_save :format_phone_numbers;
  5.  
  6. has_many :salaries
  7. has_many :feedbacks
  8. has_many :benefitplans
  9. has_one :user
  10.  
  11. def generate_access_key;
  12. self.access_key = name.crypt("o" + signupip)
  13. end
  14.  
  15. def format_phone_numbers
  16. contact_areacode = contact_areacode.gsub(/[^\d/, '')
  17. contact_phone = contact_phone.gsub(/[^\d/, '')
  18. end
  19.  
  20.  
  21. end
  22.  
  23. ##action
  24.  
  25. def create #This action is to make the rot13 key to give access to the survey application
  26. if request.post?
  27. formdata = params.fetch("organization")
  28. formdata["signupip"] = request.remote_ip
  29. begin
  30. Organization.create(formdata)
  31. flash[:notice] = "Organization created! Your access key is <strong>#{formdata["access_key"]}</strong>.<br />This key has also been emailed to you at: #{formdata["contact_email"]}</strong>."
  32. rescue => e
  33. #handle error... (e.message returns the error in a string)
  34. flash[:error] = "<strong>There was an error while signing up your organization.</strong><br />Please try again or contact us for assistance."
  35. end
  36. else # Show form, etc.
  37. end
  38. end
Add Comment
Please, Sign In to add comment