我刚刚在我的模型文件中创建了一个新的rails文件(名为project.rb
)我已经进行了以下验证:
class Project < ActiveRecord::Base
validates :title, presence: true
end
我有三个属性:title,description和due_date。但是,当我跳入我的终端并键入描述和截止日期(并且没有标题)并点击保存时,它可以正常工作!
我不明白为什么。
> p.description="lksdf" ( add description )
"lksdf"
> p.due_date="kldf" ( add due_date )
"kldf"
> p.save
(0.2ms) BEGIN
(4.6ms) COMMIT
true
2.2.0 :077 > Project.all
Project Load (0.6ms) SELECT "projects".* FROM "projects"
+----+-------------+-----------------+-----------------+----------------+-----------------+
| id | title | description | due_date | created_at | updated_at |
+----+-------------+-----------------+-----------------+----------------+-----------------+
| 1 | 1st project | this is my f... | in a weeks time | 2015-01-15 ... | 2015-01-15 1... |
| 2 | 2ndproj | 2nd slfajlsj... | next year | 2015-01-15 ... | 2015-01-15 1... |
| 3 | 3rdsdlfk | kdlajdflks;af | never haha | 2015-01-15 ... | 2015-01-15 1... |
| 4 | 4th title | lasdj | 2045 | 2015-01-15 ... | 2015-01-15 1... |
| 5 | fifth title | ldksajf | never aaja | 2015-01-15 ... | 2015-01-15 1... |
| 6 | | klsaf | slkadf | 2015-01-15 ... | 2015-01-15 1... |
| 7 | | kjldsfds | | 2015-01-15 ... | 2015-01-15 1... |
| 8 | | aljbsfalkjsdf | | 2015-01-15 ... | 2015-01-15 1... |
| 9 | | lksdf | kldf | 2015-01-15 ... | 2015-01-15 1... |
+----+-------------+-----------------+-----------------+----------------+-----------------+
9 rows in set
答案 0 :(得分:2)
我能够找出问题所在。
在重新运行我的服务器之前,我没有正确保存文件,问题解决了!