开发者

Storing navigation structure

开发者 https://www.devze.com 2023-02-19 22:19 出处:网络
I need a way to store nested navigation structure. I don\'t wan开发者_StackOverflow社区t to use database for it, storing tree-like structures there causes a lot of headache.

I need a way to store nested navigation structure. I don't wan开发者_StackOverflow社区t to use database for it, storing tree-like structures there causes a lot of headache.

I need some separate place to store this structure like text file, that i can easily change during development.

What are my best options? YAML? XML?


I personally tend to throw complex navigation structures into a helper and call it good. If you do want it external, however, I'd throw together a config/nav.yml file:

- text: Home
  url: 'root_path'
- text: Colors
  url: 'colors_path'
  nodes:
    - text: Blue
      url: 'blue_path'
    - text: Red
      url: 'red_path'

Then when the project is loaded it would load the yaml file into a global constant:

NAV = YAML.load_file(File.join(Rails.root, 'config', 'nav.yml'))

Then in the view you would iterate over the NAV constant.

0

精彩评论

暂无评论...
验证码 换一张
取 消