Lee-KangChen
Ruby on Rails now, and draw something.
2016年11月20日 星期日
validation 資料驗證
為了確認使用者輸入的資料是我們要的,就要資料驗證
使用方法很簡單,在model裡,對要驗證的欄位這樣做即可,像這樣
# app/models/group.rb
+ validates :title, presence: true
這就是要求 group table 的 title 欄位必須有資料,才能儲存
參考:
Rails 101
其他使用方法見
https://ihower.tw/rails/activerecord-lifecycle.html
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言