简体   繁体   English

如何将信息添加到自定义用户字段(Devise)

[英]How can I add information to custom user field (Devise)

I create a custom field in user (using a Devise) in my Rails project, varible called information. 我在Rails项目中(使用Devise)在用户中创建一个自定义字段,该变量称为信息。 Type is string. 类型是字符串。 Somethigh like that: current_user.information How can I add another string to end of this string? 像这样的高脚: current_user.information如何在该字符串的末尾添加另一个字符串? I need a method then do like this: 我需要一个方法,然后像这样:

current_user.information << some_varible 

And save changes. 并保存更改。

If the value of current_user.information is a string you can append to it like you stated. 如果current_user.information的值是一个字符串,则可以像声明的那样将其追加。

s = current_user.information
s << "New string addition"
s.save

Except the << method mentioned on @Rockwell's answer, you can achieve your goal by using String#concat as well: 除了@Rockwell的答案中提到的<<方法,您还可以通过使用String#concat来实现您的目标:

s = current_user.information
s.concat("New string addition")
s.save

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM