开发者

How do I write user-specific configuration into a rails app?

What is the current practice like to write user-specific configuration settings into a rails application?

For example, privacy settings in a social networking application.

I know application-wide setting开发者_运维知识库s can be stored in a .yml file in config/ but what about users?


I store user-specific information in an ActiveRecord / database model called User.


As usual it depends. if you have a few user config values store them as separate columns on User model. but if you have something more than 10 and it's probable to add other items in the future the best practice is to serialize all the config values and store them in a single column like settings.

ActiveRecord provides some helper methods to serialize data. mix these helpers with active record callbacks (before_save...) and you're good to go.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜