what is attr_accessor in datamapper - ruby

丶灬走出姿态 提交于 2019-12-06 15:46:05

Yes, you are right. It is an attribute (a field) of your model, but not in your database. You could use such attributes to keep data that shouldn't be saved in the database, but that somehow are useful for other objects in your application.

For example: you could define an accessor for a model field named "password". Then when someone sets this value, you hash it and store it in the appropriate field in the database.

It looks like the password is not stored in the database, which is good.

The password is stored in the user object only when they say first login or when they are changing their password. Since a normal ruby sinatra app essentially boots on each page load, the password is only around while it gets hashed and put into the db, etc.

In other words you can often expect that a call to obtain the password will fail. It will only work if you are still handling the login or password change event.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!