Guest User

Untitled

a guest
Dec 4th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. class User < ActiveRecord::Base
  2.  
  3. STATES = ['AL', 'AK','AZ','AR','CA','CO','CT','DE','DC','FL','GA','HI','ID','IL','IA','KS','KY','LA','ME',
  4. 'MD','MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA',
  5. 'RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY']
  6.  
  7.  
  8. validates :first_name, :last_name, :address, :city, :zipcode,
  9. :phone_number, :presence => true
  10.  
  11. validates :state, :inclusion => STATES
  12.  
  13. validates :user_name,:email_address, :presence => true, :uniqueness => true
  14. validates :password, :confirmation => true
  15.  
  16. validate :password_must_be_present
  17.  
  18. attr_accessor :password_confirmation
  19. attr_reader :password
  20.  
  21.  
  22. def password_must_be_present
  23. errors.add(:password, 'Missing Password') unless hashed_password.present?
  24. end
  25.  
  26.  
  27.  
  28. class Trainer < User
  29.  
  30.  
  31.  
  32. end
  33.  
  34.  
  35. NoMethodError in Trainers#new
  36.  
  37. Showing /Users/justin/RubymineProjects/fitness/app/views/trainers/_form.html.erb where line #16 raised:
  38.  
  39. undefined method `education' for #<Trainer:0x26b4fc0>
  40. Extracted source (around line #16):
  41.  
  42. 13:
  43. 14: <div class="field">
  44. 15: <%= f.label :education %><br />
  45. 16: <%= f.text_area :education %>
  46. 17: </div>
  47. 18: <div class="field">
  48. 19: <%= f.label :picture_url %><br />
  49. Trace of template inclusion: app/views/trainers/new.html.erb
  50.  
  51. Rails.root: /Users/justin/RubymineProjects/fitness
  52.  
  53. Application Trace | Framework Trace | Full Trace
  54. app/views/trainers/_form.html.erb:16:in `_app_views_trainers__form_html_erb___537327329_20272410_451296'
  55. app/views/trainers/_form.html.erb:1:in `_app_views_trainers__form_html_erb___537327329_20272410_451296'
  56. app/views/trainers/new.html.erb:3:in `_app_views_trainers_new_html_erb__1044883449_20278940_0'
  57. app/controllers/trainers_controller.rb:29:in `new'
  58.  
  59.  
  60. def User.encrypt_password(password, salt)
  61. Digest::SHA2.hexdigest(password + "38id!ugf%ow@e47" + salt)
  62. end
  63.  
  64. def generate_salt
  65. self.salt = self.object_id.to_s + rand.to_s
  66. end
  67.  
  68. def password=(password)
  69. @password = password
  70.  
  71. if password.present?
  72. generate_salt
  73. self.hashed_password = self.class.encrypt_password(password, salt)
  74. end
  75. end
  76.  
  77. def User.authenticate(user_name, password)
  78. if user = find_by_name(user_name)
  79. if user.hashed_password == encrypt_password(password, user.salt)
  80. user
  81. end
  82. end
  83. end
  84.  
  85. end
Add Comment
Please, Sign In to add comment