未保存/更新的嵌套属性
问题描述:
我被困在这个问题上。我可以加载查看新/编辑,但创建/更新不会更改Caracteristicas
的属性,也不保存在数据库中。 Produto
的属性根据需要进行更新。对我来说,它似乎都在正确的位置,这就是为什么我要求帮助。未保存/更新的嵌套属性
有人能指出不能够保存应用程序的问题/更新Caracteristica
?
模型
class Produto < ActiveRecord::Base
has_many :caracteristicas
attr_accessible :titulo, :caracteristicas_attributes
accepts_nested_attributes_for :caracteristicas, :reject_if => lambda { |c| c[:content].blank? }, :allow_destroy => true
end
class Caracteristica < ActiveRecord::Base
belongs_to :produto
attr_accessible :titulo, :conteudo
end
Produto控制器
def new
@produto = Produto.new
@produto.caracteristicas.build
respond_to do |format|
format.html # new.html.erb
format.json { render json: @produto }
end
end
produto.html.erb
<%= f.fields_for :caracteristicas do |builder| %>
<%= render 'caracteristica_fields', :f => builder %>
<% end %>
caracteristica_fields.html.erb
<%= f.label :conteudo %><br />
<%= f.cktext_area :conteudo, :toolbar => 'Easy' %>
创建PARAMS
{"utf8"=>"✓",
"authenticity_token"=>"mnWb2X4FiolU/mPjnZcg5nA8eYUbv9GvaBawdl9jr74=",
"produto"=>{"titulo"=>"cdsacdsacdsa",
"caracteristicas_attributes"=>{"0"=>{"conteudo"=>"<p>\r\n\t12321312</p>\r\n"},
"1356968992110"=>{"conteudo"=>"<p>\r\n\tdewdewdewdwe</p>\r\n"}}},
"commit"=>"Create Produto"}
答
我更换:
:reject_if => lambda { |c| c[:content].blank? }
与
:reject_if => lambda { |c| c[:conteudo].blank? }
谢谢你的回答:) –