Rails: Best practice to store user settings?

后端 未结 5 991
不知归路
不知归路 2020-12-14 07:43

I\'m wondering what the best way is to store user settings? For a web 2.0 app I want users to be able to select certain settings. At the moment is it only when to receive em

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 08:03

    If the user settings are not meant to be findable (via a User.find_by_x_preference, e.g.) you could also store them in a serialized column as a hash. This is the use case described in the rails docs (http://www.railsbrain.com/api/rails-2.3.2/doc/index.html?a=M002334&name=serialize#), actually.

    class User < ActiveRecord::Base
      serialize :preferences
    end
    
    u = User.new
    u.preferences = {:favorite_color => "green", :favorite_book => "Moby Dick"}
    

提交回复
热议问题