Search code examples
ruby-on-railsrubyruby-on-rails-4simple-formhstore

Integrating hstore column with simple_form in Rails 4


Is there a good way to integrate hstore with simple_form?

I just cannot find a way to achieve this. I have a column called widget_locations and I would like to store :left_area1, :mid_area1, :left_area2, :mid_area2, :right_area2 as keys and values as nested hashes so they are like below:

{:left_area1 => {:video_id => 1, :presentation_id => 3}, :mid_area1 => {:chat_id => 1, :presentation_id => 5}, :left_area2, :mid_area2, :right_area2}

Is there a best way to achieve this in simple_form?


Solution

  • You can do something like this

    <%= f.simple_fields_for :widget_locations do |location| %>
        <%= location.input :left_area1, :input_html => { :value => <value> } %>
        <%= location.input :mid_area1, :input_html => { :value => <value> } %>
    <% end %>