0

I'm stuck on this problem. I'm able to load view for new/edit but create/update don't change Caracteristicas's attributes nor save in database. The Produto's attributes are updated if needed. For me it seems to be all in the correct place, that's why I'm asking for help.

Can someone point the application's problem for not being able to save/update Caracteristica?

Models

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 controller

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' %>

create 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"}
0

1 Answer 1

1

I'd replace:

:reject_if => lambda { |c| c[:content].blank? }

with

:reject_if => lambda { |c| c[:conteudo].blank? }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.