Guest User

Untitled

a guest
Feb 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. You have a nil object when you didn't expect it!
  2. You might have expected an instance of Array.
  3. The error occured while evaluating nil.each
  4.  
  5. Extracted source (around line #12):
  6.  
  7. 9: <p>
  8. 10: <b>Title:</b><br/>
  9. 11: <select name="individual[title_id]">
  10. 12: <% @titles.each do |title| %>
  11. 13: <option value="<%= title.id %>">
  12. 14: <%= title.title %>
  13. 15: </option>
  14.  
  15.  
  16.  
  17.  
  18.  
  19. class Individual < ActiveRecord::Base
  20. belongs_to :title
  21. before_save :set_user_data
  22.  
  23. # validates_length_of :login, :within => 3..20
  24. # validates_length_of :password, :within => 8..40
  25. # validates_presence_of :login, :email, :password, :password_confirmation, :salt
  26. validates_uniqueness_of :username#, :scope => 'username', :message => "Username already in use."
  27. # validates_confirmation_of :password
  28. # validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :message => "Invalid email"
  29.  
  30.  
  31. def set_user_data
  32. salt = Time.now.strftime("%Y-%m-%d %H:%M:%S")
  33. self.birth_month = self.date_of_birth.month
  34. self.birth_day = self.date_of_birth.day
  35. self.created_on = salt
  36. newpassword = random_string(8)
  37. self.salutation = newpassword
  38. newpassword = Digest::SHA1.hexdigest(newpassword+salt)
  39. self.password = newpassword
  40. end
  41.  
  42. attr_protected :individual_id
  43.  
  44. def random_string(len)
  45. #generate a random password consisting of strings and digits
  46. chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
  47. newpass = ""
  48. 1.upto(len) { |i| newpass << chars[rand(chars.size-1)] }
  49. return newpass
  50. end
  51.  
  52. def self.authenticate(login, pass)
  53. u=find(:first, :conditions=>["login = ?", login])
  54. return nil if u.nil?
  55. return u if User.encrypt(pass, u.salt)==u.hashed_password
  56. nil
  57. end
Add Comment
Please, Sign In to add comment