0
我被困在這個問題上。我可以加載查看新/編輯,但創建/更新不會更改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"}
謝謝你的回答:) –