Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User < ActiveRecord::Base
- STATES = ['AL', 'AK','AZ','AR','CA','CO','CT','DE','DC','FL','GA','HI','ID','IL','IA','KS','KY','LA','ME',
- 'MD','MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA',
- 'RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY']
- validates :first_name, :last_name, :address, :city, :zipcode,
- :phone_number, :presence => true
- validates :state, :inclusion => STATES
- validates :user_name,:email_address, :presence => true, :uniqueness => true
- validates :password, :confirmation => true
- validate :password_must_be_present
- attr_accessor :password_confirmation
- attr_reader :password
- def password_must_be_present
- errors.add(:password, 'Missing Password') unless hashed_password.present?
- end
- class Trainer < User
- end
- NoMethodError in Trainers#new
- Showing /Users/justin/RubymineProjects/fitness/app/views/trainers/_form.html.erb where line #16 raised:
- undefined method `education' for #<Trainer:0x26b4fc0>
- Extracted source (around line #16):
- 13:
- 14: <div class="field">
- 15: <%= f.label :education %><br />
- 16: <%= f.text_area :education %>
- 17: </div>
- 18: <div class="field">
- 19: <%= f.label :picture_url %><br />
- Trace of template inclusion: app/views/trainers/new.html.erb
- Rails.root: /Users/justin/RubymineProjects/fitness
- Application Trace | Framework Trace | Full Trace
- app/views/trainers/_form.html.erb:16:in `_app_views_trainers__form_html_erb___537327329_20272410_451296'
- app/views/trainers/_form.html.erb:1:in `_app_views_trainers__form_html_erb___537327329_20272410_451296'
- app/views/trainers/new.html.erb:3:in `_app_views_trainers_new_html_erb__1044883449_20278940_0'
- app/controllers/trainers_controller.rb:29:in `new'
- def User.encrypt_password(password, salt)
- Digest::SHA2.hexdigest(password + "38id!ugf%ow@e47" + salt)
- end
- def generate_salt
- self.salt = self.object_id.to_s + rand.to_s
- end
- def password=(password)
- @password = password
- if password.present?
- generate_salt
- self.hashed_password = self.class.encrypt_password(password, salt)
- end
- end
- def User.authenticate(user_name, password)
- if user = find_by_name(user_name)
- if user.hashed_password == encrypt_password(password, user.salt)
- user
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment