在文件.yml中将字符串分成两行

丹尼尔·巴里尔

我需要在文件.yml中将字符串拆分为两行或三行。问题是,如果我尝试将最后一个字段描述分成两行,则会触发错误,因此我将其保留为一行

one:
  id: 1
  bus_company_id: 2
  seat_type_id:   1
  description:    Butacas 120º de inclinación,
                  calefacción y aire acondicionado, música funcional y video.

two:
  id: 2
  bus_company_id: 2
  seat_type_id:   2
  description:    Butacas de cuero y paño 120º de reclinación,  bandeja de apoyo
   para pies, calefacción y aire acondicionado, música funcional y video.

three:
  id: 3  
  bus_company_id: 2
  seat_type_id:   4
  description:    Butacas extra ancho de cuero y paño 150º de reclinación, bandeja de apoyo para pies,
   desayuno, almohada y frazada, sistema de DVD y MP3.

four:
  id: 4 
  bus_company_id: 2
  seat_type_id:   5
  description:    Butacas de cuero 180º reclinación, bandeja de apoyo para pies de 180º de reclinación, cortina divisoria, almohada y frazadas sonido sourround, sistema de DVD y MP3, aire y calefacción, menú a elección de carne, pollo o verdura  para su cena.

触发此错误。

fernando@fernando:~/ProyectoTicketMaster/TicketMaster$ rake db:seed
rake aborted!
ActiveRecord::Fixture::FormatError: a YAML error occurred parsing /home/fernando/ProyectoTicketMaster/TicketMaster/test/fixtures/bus_seat_types.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html
The exact error was:
  Psych::SyntaxError: (<unknown>): could not find expected ':' while scanning a simple key at line 27 column 3
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activerecord-3.2.19/lib/active_record/fixtures/file.rb:43:in `rows'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activerecord-3.2.19/lib/active_record/fixtures/file.rb:29:in `each'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activerecord-3.2.19/lib/active_record/fixtures.rb:670:in `block (2 levels) in read_fixture_files'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activerecord-3.2.19/lib/active_record/fixtures/file.rb:20:in `open'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activerecord-3.2.19/lib/active_record/fixtures.rb:669:in `block in read_fixture_files'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activerecord-3.2.19/lib/active_record/fixtures.rb:668:in `each'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activerecord-3.2.19/lib/active_record/fixtures.rb:668:in `read_fixture_files'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activerecord-3.2.19/lib/active_record/fixtures.rb:548:in `initialize'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activerecord-3.2.19/lib/active_record/fixtures.rb:482:in `new'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activerecord-3.2.19/lib/active_record/fixtures.rb:482:in `block (2 levels) in create_fixtures'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activerecord-3.2.19/lib/active_record/fixtures.rb:479:in `map'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activerecord-3.2.19/lib/active_record/fixtures.rb:479:in `block in create_fixtures'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:232:in `disable_referential_integrity'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activerecord-3.2.19/lib/active_record/fixtures.rb:476:in `create_fixtures'
/home/fernando/ProyectoTicketMaster/TicketMaster/db/seeds.rb:15:in `<top (required)>'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:245:in `load'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:245:in `block in load'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:245:in `load'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/railties-3.2.19/lib/rails/engine.rb:525:in `load_seed'
/home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/activerecord-3.2.19/lib/active_record/railties/databases.rake:347:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)
fernando@fernando:~/ProyectoTicketMaster/TicketMaster$ 
每小时

我认为您想使用此处描述的换行符格式看来您有两个选择,这是我使用“>”表示法汇总的一个简单示例。

parse.rb文件在这里:

require 'yaml'
foo = YAML.load_file('foo.yaml')
puts foo

这是YAML文件的内容:

one_line: one line of text
two_lines:
>
this is a couple lines of text
here we go...
final_line: final line of content

当您通过命令行使用来运行此命令时ruby parse.rb,您将获得以下输出:

{"one_line"=>"one line of text", "two_lines"=>"this is a couple lines of text here we go...\n", "final_line"=>"final line of content"}

希望这是有道理的。我认为您只需要添加“>”并将文本移到下一行。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

BAT文件以两行替换字符串

来自分类Dev

使用linux命令在文件的两行之间查找字符串

来自分类Dev

在文件中查找字符串,然后删除两行

来自分类Dev

将字符串分成两行

来自分类Dev

c ++如何从文本文件中将一行分成两行,然后分别存储到两个不同的数组中?

来自分类Dev

在PHP中将字符串拆分为两行

来自分类Dev

在Java中将字符串写入文件

来自分类Dev

如何将字符串数组分成两个文件M C ++ 98 / VS2010

来自分类Dev

如何使用两个字符分隔符将字符串分成两行

来自分类Dev

在MATLAB中将以行分隔的字符串文本文件读取为字符串向量

来自分类Dev

如何从yml文件中的变量更改字符串?

来自分类Dev

如何在python中将文件的行读取为列表而不是字符串

来自分类Dev

迭代两个文件,比较行中匹配的字符串,合并匹配的行

来自分类Dev

打印文件并两行减去

来自分类Dev

绕过 csv 文件的前两行

来自分类Dev

如何将一个非显式给定的字符串分成两行或多行?

来自分类Dev

在codeigniter中将字符串分成两个

来自分类Dev

在Matlab中将字符串分成两部分

来自分类Dev

在codeigniter中将字符串分成两个

来自分类Dev

在Matlab中将字符串分成两部分

来自分类Dev

匹配两个文件之间的行并标记匹配的字符串

来自分类Dev

如何使用python比较来自两个不同文件的行字符串?

来自分类Dev

汇编中将字符串写入文件100次

来自分类Dev

在JavaScript中将字符串前置到文件?

来自分类Dev

在CSV文件中将字符串插入Matlab

来自分类Dev

在PHP中将大字符串写入文件

来自分类Dev

在jQuery / JS中将文件读取为字符串

来自分类Dev

在Java中将字符串作为字节写入文件

来自分类Dev

在Scala中将字符串写入新文件

Related 相关文章

  1. 1

    BAT文件以两行替换字符串

  2. 2

    使用linux命令在文件的两行之间查找字符串

  3. 3

    在文件中查找字符串,然后删除两行

  4. 4

    将字符串分成两行

  5. 5

    c ++如何从文本文件中将一行分成两行,然后分别存储到两个不同的数组中?

  6. 6

    在PHP中将字符串拆分为两行

  7. 7

    在Java中将字符串写入文件

  8. 8

    如何将字符串数组分成两个文件M C ++ 98 / VS2010

  9. 9

    如何使用两个字符分隔符将字符串分成两行

  10. 10

    在MATLAB中将以行分隔的字符串文本文件读取为字符串向量

  11. 11

    如何从yml文件中的变量更改字符串?

  12. 12

    如何在python中将文件的行读取为列表而不是字符串

  13. 13

    迭代两个文件,比较行中匹配的字符串,合并匹配的行

  14. 14

    打印文件并两行减去

  15. 15

    绕过 csv 文件的前两行

  16. 16

    如何将一个非显式给定的字符串分成两行或多行?

  17. 17

    在codeigniter中将字符串分成两个

  18. 18

    在Matlab中将字符串分成两部分

  19. 19

    在codeigniter中将字符串分成两个

  20. 20

    在Matlab中将字符串分成两部分

  21. 21

    匹配两个文件之间的行并标记匹配的字符串

  22. 22

    如何使用python比较来自两个不同文件的行字符串?

  23. 23

    汇编中将字符串写入文件100次

  24. 24

    在JavaScript中将字符串前置到文件?

  25. 25

    在CSV文件中将字符串插入Matlab

  26. 26

    在PHP中将大字符串写入文件

  27. 27

    在jQuery / JS中将文件读取为字符串

  28. 28

    在Java中将字符串作为字节写入文件

  29. 29

    在Scala中将字符串写入新文件

热门标签

归档