Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
创建包含“screen_name”属性的用户时,我想将名为“username”的用户属性的值设置为 screen_name 的值,但默认情况下是小写。
我正在使用活动记录和导轨,对此最好的解决方案是什么?
谢谢
您可以before_create在文件中添加过滤器app/models/user.rb:
before_create
app/models/user.rb
before_create :set_username def set_username self.username = screen_name.downcase end