简体   繁体   中英

Read remote yaml ruby on rails

I want to read a remote .yaml file (in my case, file is in 'Public' file in Dropbox) and to parse it so that in the end I have a hash.

When I try something like open('https://link_to_file/file.yaml') , I get not File object but a string object, so I cannot just YAML.load(open('https://link_to_file/file.yaml'))

The question is: how do I change string object like

foo:
    -foo1
    -foo2

(which is actually something like "foo:\\r\\n\\t-foo1\\r\\n\\t-foo2" )

to a yaml-like hash?

Use YAML.parse instead:

YAML.parse(open('https://link_to_file/file.yaml'))

And as @VoloD stated:

after you use parse , use .to_ruby to retrieve a hash.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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