将表中的现有值附加为字符串

时间:2016-08-20 08:27:05

标签: ruby-on-rails

在提交操作(来自我的标准RoR编辑视图)中,我想将现有数据字段存储为同一行中正在进行的文本转储。

控制器应该"推"数据字段的值(例如current_location)到表格text中的logdump\n作为分隔符。

经过一些旅行和改变" current_location"会有例如存储在表格域logdump中的以下文本: London Rio Athen Berlin New York

我想过将这个日志存储在一个额外的日志表中,但是这个字符串转储解决方案已经存在于我现有的表中,足以满足我的需求。

1 个答案:

答案 0 :(得分:0)

你可能需要序列化它

class User < ActiveRecord::Base
  serialize :current_location, Array
end

u = User.new
#=> #<User id: nil, current_location: [], created_at: nil, updated_at: nil>
u.current_location = %w(London Rio Athen Berlin New\ York)
u.save