A serialized attribute accessor gem with support for types and defaults
Serializer is a Ruby on Rails tool for adding accessor to serialized attributes with support for types and defaults.
The gem is tested with:
gem install serializer
Migration:
rails g model user name:string email:string settings:text
Model:
class User < ActiveRecord::Base
has_serialized :settings do |settings|
settings.define :tw_share, type: :boolean, default: true
settings.define :fb_share, type: :boolean, default: true
settings.define :completion, type: :float, default: 50.0
end
end
Form:
<%# form_for @user do |form| %>
<%# form.text_field :name %>
<%# form.email_field :email %>
<%# form.checkbox_box :tw_share %>
<%# form.checkbox_box :fb_share %>
<% end %>
View:
<%- if @user.tw_share? -%>
...
<%- end -%>
<%- if @user.fb_share? -%>
...
<%- end -%>
Copyright (c) 2010 - 2012 Kevin Sylvestre. See LICENSE for details.