Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I grappled with this same question so I thought I'd share what I found in a "community wiki" answer.</p> <h3>Serializing in a single attribute</h3> <p><a href="http://blog.project-sierra.de/archives/1379" rel="nofollow noreferrer">Simple user preferences for your Rails app</a> is a blog post describing how to do this.</p> <p><a href="https://stackoverflow.com/questions/6539991/edit-a-serialized-hash-in-a-form">Edit a serialized hash in a form?</a> describes how to edit such a hash in a form. A helpful trick is to make the form from <code>OpenStruct.new(@user.preferences)</code> hash to automatically make accessor methods for each hash attribute.</p> <p><a href="https://github.com/DYE/has_serialized" rel="nofollow noreferrer">DYE/has_serialized - GitHub</a> lets you treat those attributes in the serialized hash as attributes on the (user) model.</p> <h3>Preferences in a separate table</h3> <p><a href="https://stackoverflow.com/questions/1682089/rails-best-practice-to-store-user-settings">Best practice to store user settings?</a> has some tips. Below are some libs including two from another answer by @hopeless.</p> <ul> <li><a href="https://github.com/ledermann/rails-settings" rel="nofollow noreferrer">rails-settings</a> manages a table of key/value pairs like a Hash stored in you database, using simple ActiveRecord like methods for manipulation. You can store any kind of object: Strings, numbers, arrays, or any object which can be noted as YAML. (Tested with Rails 3.1 and newer including Rails 4.x and Rails 5.x)</li> <li><a href="http://github.com/brennandunn/preference%5Ffu/tree/master" rel="nofollow noreferrer">Preference-fu</a> is good for simple boolean preferences, uses a single column for multiple preferences.(last updated 2009)</li> <li><a href="http://github.com/pluginaweek/preferences/tree/master" rel="nofollow noreferrer">Preferences</a> is more flexible, uses a separate table, some nice syntactic sugar. (last updated 2011)</li> <li><a href="https://github.com/cjbottaro/has_easy" rel="nofollow noreferrer">HasEasy</a> stores the data in a vertical table, but allows you to add validations, pre/post storage processing, types, etc. (Last updated 2008)</li> </ul> <p>You can also try using metaprogramming: <a href="http://www.kalzumeus.com/2009/11/17/practical-metaprogramming-with-ruby-storing-preferences/" rel="nofollow noreferrer">Practical Metaprogramming with Ruby: Storing Preferences</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload