Last Updated: February 25, 2016
·
3.283K
· shinn

hstore and Rails Form

Working with hstore in Rails is fun; however when using it with Rails form builder, it does not repopulate the data because of its key and value properties. Fortunately this can be solved easily by using OpenStruct.

<%= f.fields_for :parts, OpenStruct.new(f.object.parts) do |p| %>
    <%= p.label :keyboard %>
    <%= p.text_field :keyboard %>
<% end %>