0

I have a yaml file of application settings (arrays and hashes) that I would like a user to be able to edit through a view. What is the best way to do this?

Load the yaml file into an object that the view helper fields_for can use? So an ActiveModel or OpenStruct object?

These are application settings and are not associated with a particular user.

In the end I used an interim active record object with a serialze column as advised by Dmitri and then can use YAML.dump(app_config.settings, file) to create a yaml file

4

1 回答 1

1

为什么要将用户的设置存储在 YAML 文件中?在用户表中创建一个列并为该列添加一个序列化规则不是更容易吗 - 它会产生几乎相同的结果,并且您将能够使用您需要的所有东西而没有任何痛苦

如果你那么固执,那么为用户的控制器创建一个单独的操作并发布一个form_tag(即无模型行为)表单,然后应用所有逻辑来重写文件中的数据,例如.. YAML.load_file,更新和回写到文件。

于 2013-10-18T18:30:04.817 回答