Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "builder", "parent_builder", and "namespace" fields returned from Postgresql/Hstore in rails

I built a simple application, which i am trying to update with a form, but got some weirdness going on.

I have a column 'field_items' which is an hStore. If i call debug on the model in my view...

<%= debug @app.field_items %>

I get the two proper items returned. In the rails console i also do not see the three extras.

I have a form_for where i iterate over the 'field_items'

In my form it returns three extra fields "builder", "parent_builder", and "namespace"

Anyone have any ideas? I have noticed if i comment out the serialize line on :field_items in the model, it doesn't return the three extra attributes


Here is my model

class App < ActiveRecord::Base
  belongs_to :page
  attr_accessible :content, :title, :layouts, :field_items

  serialize :layouts, ActiveRecord::Coders::Hstore
  serialize :field_items, ActiveRecord::Coders::Hstore  
end

Here is the form/code from my edit view

<%= form_for [:admin, @app], :html => { :class => "form app_fields_form" } do |f| -%>
    <div id="app_fields_row_container">
        <%= f.fields_for :field_items, @app.field_items do |fi| %>
            <% @app.field_items.try(:each) do |key, value| %>
                <div class='app_fields_row item_row'>
                    <div class="column col1"><%= text_field_tag key, key, :class => "form_text_field dynamic_attr" %></div>
                    <div class="column col2"><%= fi.select key, options_for_select(APP_FIELD_TYPES, value), {}, {:class => "form_select"} %></div>
                    <div class="column col3"><a href="#" class="adm_button h_red small grey app_fields_delete">x</a></div>
                </div>
            <% end %>
        <%- end -%>
    </div>  
<% end -%>
like image 360
Joel Grannas Avatar asked Sep 12 '25 11:09

Joel Grannas


2 Answers

I was having the same issue. Removing @app.field_items from fields_for worked for me

<%= f.fields_for :field_items do |fi| %>
like image 185
Dmitriy Avatar answered Sep 14 '25 00:09

Dmitriy


Remove the following line and it should work fine:

<%= f.fields_for :field_items, @app.field_items do |fi| %>

I had the exact same problem, and removing the fields_for call solved the issue, as there is no need for it as it isn't a nested resource.

like image 37
Benoit E. LeBlanc Avatar answered Sep 14 '25 01:09

Benoit E. LeBlanc