不使用嵌套属性的字段 rails
Fields for not working with nested attributes rails
出于某种原因 fields_for 没有显示我的嵌套属性文本框。我已经按照有关如何让它工作的指南进行操作,但仍然是零运气。任何帮助将不胜感激。
*奇怪的是,我曾使用 Oracle 作为数据库,然后切换到 Sqlserver,但现在它不起作用。
这是我的入门模型
class Entry < ActiveRecord::Base
include WorkorderTranslator
belongs_to :release
belongs_to :session
belongs_to :sheet
has_many :stm_entries, :dependent => :destroy
attr_protected :id
accepts_nested_attributes_for :stm_entries
class StmEntry < ActiveRecord::Base
self.primary_key = 'id'
belongs_to :entry
attr_protected :id
这是我的看法
-if current.stm?
-e.stm_entries.each do |stm|
%tr{:id => (stm.editable == true ? 'target' : '') }
%td.b.trace-table= e.trace_number
=render "heat_form", :entry => e, :f => f
-if stm.editable == true
=f.simple_fields_for :stm_entries, stm do |ff|
%td.b.trace-table{:style => 'padding-top:3px;'}
= ff.input :date, :as => :string, :readonly => true, :input_html => {:style => 'width:90%;', :value => (ff.object.date.nil? ? Date.today.strftime("%m/%d/%Y") : ff.object.date.strftime("%m/%d/%Y")), :placeholder => 'Date', :class => 'floatlabel'}, :label => false
%td.b.trace-table{:style => 'padding-top:3px;'}
= ff.input :user, :readonly => true, :input_html => {:style => 'width:90%;', :placeholder => 'User ID', :class => 'floatlabel'}, :label => false
%td.b.trace-table{:style => 'padding-top:3px;'}
= ff.input :splices, :label => false, :input_html => {:style => 'width:90%;', :placeholder => 'Splices', :class => 'floatlabel'}
所以当我切换数据库时(我在 Oracle 上移动到 SqlServer)我手动创建了我的表。在做一些搞砸的事情(外键,主键问题)。所以我只是做了一个耙子 db:migrate 并且很快它就起作用了。
出于某种原因 fields_for 没有显示我的嵌套属性文本框。我已经按照有关如何让它工作的指南进行操作,但仍然是零运气。任何帮助将不胜感激。
*奇怪的是,我曾使用 Oracle 作为数据库,然后切换到 Sqlserver,但现在它不起作用。
这是我的入门模型
class Entry < ActiveRecord::Base
include WorkorderTranslator
belongs_to :release
belongs_to :session
belongs_to :sheet
has_many :stm_entries, :dependent => :destroy
attr_protected :id
accepts_nested_attributes_for :stm_entries
class StmEntry < ActiveRecord::Base
self.primary_key = 'id'
belongs_to :entry
attr_protected :id
这是我的看法
-if current.stm?
-e.stm_entries.each do |stm|
%tr{:id => (stm.editable == true ? 'target' : '') }
%td.b.trace-table= e.trace_number
=render "heat_form", :entry => e, :f => f
-if stm.editable == true
=f.simple_fields_for :stm_entries, stm do |ff|
%td.b.trace-table{:style => 'padding-top:3px;'}
= ff.input :date, :as => :string, :readonly => true, :input_html => {:style => 'width:90%;', :value => (ff.object.date.nil? ? Date.today.strftime("%m/%d/%Y") : ff.object.date.strftime("%m/%d/%Y")), :placeholder => 'Date', :class => 'floatlabel'}, :label => false
%td.b.trace-table{:style => 'padding-top:3px;'}
= ff.input :user, :readonly => true, :input_html => {:style => 'width:90%;', :placeholder => 'User ID', :class => 'floatlabel'}, :label => false
%td.b.trace-table{:style => 'padding-top:3px;'}
= ff.input :splices, :label => false, :input_html => {:style => 'width:90%;', :placeholder => 'Splices', :class => 'floatlabel'}
所以当我切换数据库时(我在 Oracle 上移动到 SqlServer)我手动创建了我的表。在做一些搞砸的事情(外键,主键问题)。所以我只是做了一个耙子 db:migrate 并且很快它就起作用了。