class Prescription < ActiveRecord::Base
belongs_to :user
validates :time, presence:true
validates :user_id, presence:true
#I want to access an attribute from the user model, but this does not work:
num = self.user.mobilephone
END
正如你所看到的,我使用的ActiveRecord並有belongs_to
協會,所以不應該訪問的用戶屬性很容易內引用另外一個模型?(Ruby on Rails的初學者)的模型
@ user313330用您的問題添加更多細節。 – 2015-12-03 02:35:09