Rails:指定 yml 中的项目列表
我想在 yml 文件中指定资源授权信息。管理员可以创建员工,只能查看公司。
我使用 YAML::load 方法来加载该文件。
如果我使用 - 符号表示多个权限(操作、资源对),则会出现解析错误。如果我删除 - 符号,那么它只选择第一个操作资源对。我认为加载方法在解析时期望 1 个空格缩进,并且如果我指定 - 则违反了 1 个空格缩进条件,这就是错误的原因。有什么可能的解决方案。
如果我使用 - 符号列出
admin:
- action: create
resource: employee
- action: show
resource: company
如果我不使用 - 符号列出
admin:
action: create
resource: employee
action: show
resource: company
I want to specify resource authorisation info in yml file. admin can create an employee and can only view company.
I used YAML::load method to load this file.
If i use - symbol for multiple permission (action, resource pair) it gives parsing error. If i remove - symbol then it only picks first action resource pair. I think load method expect 1 space indentation while parsing and if i specify - then one space indentation condition is violated that is reason for error. What is possible solution for this.
if i use - symbol for listing
admin:
- action: create
resource: employee
- action: show
resource: company
if i do not use - symbol for listing
admin:
action: create
resource: employee
action: show
resource: company
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定这是否有帮助,但是当我尝试加载第一个示例时,它对我有用。也许缩进不正确?
不管怎样,这在这里有效:
require "YAML"
some = YAML.load_file("admin.yaml")
哦,是的,让我添加适合我的 admin.yaml :
not sure if this helps, but when i try to load the first example, it works for me. Maybe the indentation is not correct?
anyway, this works here:
require "YAML"
something = YAML.load_file("admin.yaml")
oh yes, let me add the admin.yaml that works for me:
如果您在生成 YAML 时遇到问题,我会尝试在控制台中构建一个对象,然后将其转换为 YAML 以查看其外观。例如:
如果它使您的生活更轻松,您甚至可以将其输出到文件中:
其结果:
我还没有完全匹配您上面的内容,因为我使用了符号作为键,但这应该可以帮助您。
If you're having trouble generating YAML, I would try building an object in the console, then converting it to YAML to see what it looks like. For example:
You can even output it to a file if it makes your life easier:
Which yields:
I haven't quite matched what you have above, since I used symbols for keys, but this should help you out I hope.