I have a user model. like
class User < ActiveRecord::Base
attr_accessor :username :campaign_id
attr_accessible :name, :email, :username
end
if i fetch one user record like
u = User.first
it will return
#<User id: 190, name: "sa", :email: "[email protected]", username: "ab">
So the question is: Is there any way to check whether one attribute e.g. 'name' is a attr_accessor or attr_accessible?
If I understand correctly, the devise attr_accessor :password
hides your password field in the database. To circumvent this, you could do something like
def raw_password
self[:password]
end
def raw_password= (new_password)
self[:password] = new_password
end
Of course, this is completely disregarding the fact that is not very safe to store the password in cleartext in the database. Devise offers enough mechanisms for users to manage their own password, so you should not be keeping the raw password for much longer.
Perhaps not the best solution, but by looking at the source code I guess you could check if :name
appears in the _accessible_attributes
field of your class or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With