ruby-on-rails – Rails教程 – 2.5.2无法获得有效的运动
我正在参与第2章末尾练习的Rails教程,我很难过.
www.railstutorial.org/book/toy_app#sec-toy_app_exercises 作业2说:“通过用适当的代码替换FILL_IN来更新清单2.19,以验证用户模型中是否存在名称和电子邮件属性(图2.20).” 这很直接 Adding presence validations to the User model. app/models/user.rb class User < ActiveRecord::Base has_many :microposts validates FILL_IN,presence: true validates FILL_IN,presence: true end 我做的第一件事是典型的noob错误,只是直接从列表中复制代码.系统回来后问我这个变量“FILL_IN”是什么. 我做的下一件事是尝试在我的user.rb文件中输入字段名称 class User < ActiveRecord::Base has_many :microposts validates name,presence: true validates email,presence: true end Running this,gets me a the following error Rails表现得像是无法识别电子邮件,或者从我的模型中命名字段. 我已经尝试过将名称和电子邮件大写,我试过让它们复数,我试图去“rails console”来验证我是否正确创建了“名称”和“电子邮件”字段(我做过). 我试过寻找答案,我来的衣柜是someone just pasting in the FILL_IN lines and getting harpooned for it. 我希望我没有错过任何明显的东西,但如果我做的话,我已经做好了准备. 解决方法
@章鱼保罗
真棒,变量名前的冒号(:)正是我所需要的. class User < ActiveRecord::Base has_many :microposts validates :name,presence: true validates :email,presence: true end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |