i'm trying to put in the "client" form an nested fields_for to add his address at same time. Followed this video: https://www.youtube.com/watch?v=fsgTT9hizZo which shows what i need.
well this is my code:
cliente model =>
class Cliente < ActiveRecord::Base
has_one :local
accepts_nested_attributes_for :local
end
local model=>
class Local < ActiveRecord::Base
belongs_to :cliente
end
cliente controller =>
def new
@cliente = Cliente.new
@cliente.build_local
end
def cliente_params
params.require(:cliente).permit(:name, :telefone, :celular, :email, :local_attributes => [:logra, :cep, :uf, :city, :km])
end
cliente view
<%= f.fields_for :local do |ff| %>
<td> <%= ff.text_field :km %> </td>
And the error = undefined method `build_local' for # in the cliente_controller.rb
Give this a try-
instead of -