मैं रेल के लिए कुछ नया हूं और मैं उपयोगकर्ता लॉगिन बनाने की कोशिश कर रहा हूं। मैं ट्यूटोरियल के माध्यम से here मिला। अंत में यह मुझे बड़े पैमाने पर असाइनमेंट के लिए "attr_accessible" जोड़ दिया था।अपरिभाषित विधि attr_accessible
undefined method `attr_accessible' for #<Class:0x007ff70f276010>
मैं इस post कि मैं neeed < ActiveRecord :: बेस पर देखा: लेकिन जब मुझे लगता है कि मैं निम्नलिखित त्रुटि मिली थी। लेकिन मेरे पास यह शामिल है। मेरे उपयोगकर्ता मॉडल के लिए कोड यहां दिया गया है:
class User < ActiveRecord::Base
attr_accessor :password
EMAIL_REGEX = /\A[A-Z0-9._%+-][email protected][A-Z0-9.-]+\.[A-Z]{2,4}\z/i
validates :username, :presence => true, :uniqueness => true, :length => { :in => 3..20 }
validates :email, :presence => true, :uniqueness => true, :format => EMAIL_REGEX
validates :password, :confirmation => true #password_confirmation attr
validates_length_of :password, :in => 6..20, :on => :create
before_save :encrypt_password
after_save :clear_password
attr_accessible :username, :email, :password, :password_confirmation
def encrypt_password
if password.present?
self.salt = BCrypt::Engine.generate_salt
self.encrypted_password= BCrypt::Engine.hash_secret(password, salt)
end
end
def clear_password
self.password = nil
end
end
इस समस्या का कारण बनने के बारे में कोई अन्य विचार वास्तव में सराहना की जाएगी, धन्यवाद!
संपादित करें: रेल 4.1 पर। ऐसा लगता है कि यह अब लागू नहीं होता है। धन्यवाद fotanus
[यहां पढ़ें] (http://stackoverflow.com/questions/17371334/how-is-attr-accessible-used-in-rails-4)। अपने प्रश्न को सही रेल संस्करण के साथ ठीक करें, क्योंकि यह इस प्रश्न के लिए महत्वपूर्ण है। – fotanus