看板 Ruby 關於我們 聯絡資訊
最近在學Ruby on Rails. 挑了Ruby On Rails Tutorial 3作為我的入門書 在本書中的Ch7的Listing 7.2的程式碼有點疑惑, 我打在下面 Listing 7.2 Validations for the password attribute. app/models/user.rb class User < ActiveRecord::Base attr_accessor :password attr_accessible :name, :email, :password, :password_confirmation # Automatically create the virtual attribute 'password_confirmation'. validates :password, :presence => true, :confirmation => true, :length => { :within => 6..40 } end 我的問題是..在attr_accessible中的 :password_confirmation與 下列那註解裡面所提到的password_confirmation是同一個東西嗎? 書本裡面提到: we will not introduce a password_confirmation attribute, not even a virtual one. Instead, we will use the special validation: validate :password, :confirmation => true which will automatically create a virtual attribute called "password_confirmation"..(以下略 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.240.169.84