Rails Console: reload! not reflecting changes in model files? What could be possible reason?

人走茶凉 提交于 2019-11-27 03:36:53
Nazar Hussain

reload! only reloads the latest code in the console environment. It does not re-initialize existing objects.

This means if you have already instantiated any objects, their attributes would not be updated - including newly introduced validations. However, if you create a new object, its attributes (and also validations) will reflect the reloaded code. more here

Are you reloading the object from the database?

For example:

>> a = User.last
=> #<User id: 16, email: "asdfadsf@sdfdsf.com">
>> reload!
Reloading...
=> true

'a' won't reflect any changes to your model until you reload it from the db.

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