3

我构建了一个简单的应用程序,我试图用一个表单来更新它,但是发生了一些奇怪的事情。

我有一列'field_items',它是一个hStore。如果我在我看来对模型调用调试...

<%= debug @app.field_items %>

我得到了两个正确的项目返回。在 Rails 控制台中,我也看不到三个附加功能。

我有一个 form_for,我在其中迭代“field_items”

在我的表单中,它返回三个额外字段“builder”、“parent_builder”和“namespace”

有人有想法么?我注意到如果我在模型中注释掉 :field_items 上的序列化行,它不会返回三个额外的属性


这是我的模型

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

这是我的编辑视图中的表单/代码

<%= 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 -%>
4

2 回答 2

2

我遇到了同样的问题。从 fields_for 中删除 @app.field_items 对我有用

<%= f.fields_for :field_items do |fi| %>
于 2013-06-13T06:18:06.887 回答
1

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.

于 2013-03-06T13:32:57.877 回答