0

Rails 4 には、 と との関係を持つメッセージ モデルがuserありtemplateます。また、独自の属性 、 を持っていますtext

class Message < ActiveRecord::Base
attr_accessor :text

belongs_to :user
belongs_to :template

validates :user, presence: true
validates :template, presence: true
validates :text, presence: true, if: lambda { |message| message.template.present? }

    def initialize(args = {})
      super
      @user = args[:user]
      @template = args[:template]
      @text = args[:text] || (args[:template].text if args[:template].present?)
    end

end

ここに私の問題があります: (既にと があるuserと仮定します) 実行すると に等しくなりますが、データベースからこのレコードを取得すると、属性はであり、他のすべての属性は問題ありません。templatemessage = Message.create!(user: user, template: template, "hello world") message.text"hello world"textnil

何を与える?textデータベースに永続化されていないのはなぜですか?

4

1 に答える 1