rails 5.2 model attributes assignment 要注意的地方
當透過 association build model 時,要注意 value assignment 的順序

user.profiles.new(mobile: '0988123456')
我們知道上面這段 code 得到的 profile model,裡面的 value 會有 user_id 和 mobile
不過 assignment 的順序是 mobile -> user_id
所以當你 overwrite setter method 時,例如
def mobile=(value) user.country_code + value.to_s end
這時 user 肯定是 null
所以得把這樣的處理移到 before_save 或先 new 出來後再 assign_attributes 才行。
延伸閱讀
加入 BNI 商會心得
於 2023/10 加入了 BNI 台南商會(大信白金),本篇文章將分享加入後的心得,並持續更新心得內容,確認在不同階段的自己是否有偏離初衷。
rails app(web) 嵌入到 iframe 中
ruby on rails 的 web 預設是無法嵌入到 HTML iframe 中的,本篇文章將教學如何使其成功在不同網域中將 rails web 成功嵌入到 iframe 中。
設定電子郵件 DMARC
提供設定 DMARC 的範例,並且提供官方語法說明和檢測工具連結。