Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 368
Passionate Engineer Avatar asked Jan 20 '14 15:01

Passionate Engineer


1 Answers

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 %>
like image 73
usha Avatar answered Nov 06 '22 09:11

usha