我从一个联系不上的同事那里收到了这个yml数据文件。我需要加载它来获取数据,但我不确定如何加载:
---
- !ruby/object:Question
concise_attributes:
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: id
value_before_type_cast: 1
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: name
value_before_type_cast: Trip Summary
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: question
value_before_type_cast: Please state your general feelings about itinerary, the
group, and the operations. How did it go overall?
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: created_at
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: updated_at
new_record: false
active_record_yaml_version: 2
- !ruby/object:Question
concise_attributes:
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: id
value_before_type_cast: 2
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: name
value_before_type_cast: Itinerary
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: question
value_before_type_cast: Did you and the clients like the itinerary? If not, why
not? How could it be improved? Was it accurate? Did you make any adjustments
to the itinerary? Please describe any special things you did on the trip that
were not part of the itinerary.
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: created_at
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: updated_at
new_record: false
active_record_yaml_version: 2我的第一个猜测是使用yaml_db gem,然后直接使用YAML::load_file本身,但我得到了错误:
ArgumentError: undefined class/module Question即使应用程序中有一个问题模型“
class Question < ActiveRecord::Base
end发布于 2019-01-03 04:11:43
它似乎是用ActiveModel::AttributeSet::YAMLEncoder编码的。您可以使用decode方法来解析yaml文件。concise_attributes的使用是YAMLEncoder所特有的。
编辑:当文件在ActiveModel下时,使用ActiveRecord::AttributeSet::YAMLEncoder在控制台中加载它
https://stackoverflow.com/questions/54012348
复制相似问题