我有很強的參數在軌道4,5和angularjs,在我收到以下錯誤控制器內我的方法更新一個問題:方法更新和錯誤unpermited參數軌道4
不允許的參數:ID,cliente_id,created_at,的updated_at 未經許可參數:ID,cliente_id,created_at,的updated_at 未經許可的參數:ID,cliente_id,created_at,的updated_at 未經許可的參數:ID,cliente_id,created_at,的updated_at 未經許可的參數:ID,cliente_id,created_at,的updated_at 未經許可的參數:id ,cliente_id,created_at,updated_at 未經許可的參數:id,cliente_ ID,created_at,的updated_at 不允許的參數:ID,格式,cliente
這裏是我的JSON發送:
{
"id"=>"52",
"CliERP"=>"C-00125",
"CliRazao"=>"CHOCOLANDIA COMERCIO DE CHOCOLATES LTDA.",
"CliCNPJ"=>"55946756000110",
"CliEmail"=>"[email protected]",
"CliObs"=>"TESTE\nTESTE CHOCOMANIA 123456",
"enderecos_attributes"=>[
{
"id"=>52,
"cliente_id"=>52,
"EndTipo"=>"E",
"EndCEP"=>"78456441",
"EndLogradouro"=>"RUA IPIRANGA",
"EndNumero"=>"2500",
"EndBairro"=>"CENTRO",
"EndCidade"=>"PORTO ALEGRE",
"EndEstado"=>"RS",
"created_at"=>"2016-04-30T18:00:11.249Z",
"updated_at"=>"2016-04-30T18:00:11.249Z"
}
],
"telefones_attributes"=>[
{
"id"=>3,
"cliente_id"=>52,
"TelTipo"=>"F",
"TelNumero"=>"7843257896",
"created_at"=>"2016-04-30T18:00:11.251Z",
"updated_at"=>"2016-04-30T18:00:11.251Z"
},
{
"id"=>4,
"cliente_id"=>52,
"TelTipo"=>"F",
"TelNumero"=>"7845214563",
"created_at"=>"2016-04-30T18:00:11.254Z",
"updated_at"=>"2016-04-30T18:00:11.254Z"
},
{
"id"=>5,
"cliente_id"=>52,
"TelTipo"=>"C",
"TelNumero"=>"78996568941",
"created_at"=>"2016-04-30T18:00:11.257Z",
"updated_at"=>"2016-04-30T18:00:11.257Z"
}
],
"emails_attributes"=>[
{
"id"=>1,
"cliente_id"=>52,
"MailTipo"=>"E",
"MailEndereco"=>"[email protected]",
"created_at"=>"2016-04-30T18:00:11.261Z",
"updated_at"=>"2016-04-30T18:00:11.261Z"
},
{
"id"=>2,
"cliente_id"=>52,
"MailTipo"=>"E",
"MailEndereco"=>"[email protected]",
"created_at"=>"2016-04-30T18:00:11.275Z",
"updated_at"=>"2016-04-30T18:00:11.275Z"
},
{
"id"=>3,
"cliente_id"=>52,
"MailTipo"=>"E",
"MailEndereco"=>"[email protected]",
"created_at"=>"2016-04-30T18:00:11.277Z",
"updated_at"=>"2016-04-30T18:00:11.277Z"
}
]
}
這是我的控制器:
class ClientesController < ApplicationController
def index
@clientes = Cliente.all
end
def show
@clientes = Cliente.find(params[:id])
@clientes.enderecos = Endereco.where("cliente_id = ?", params[:id])
@clientes.telefones = Telefone.where("cliente_id = ?", params[:id])
@clientes.emails = Email.where("cliente_id = ?", params[:id])
#logger.debug "RETORNO => #{@clientes.inspect}"
end
def create
@cliente = Cliente.new(cliente_params)
respond_to do |format|
if @cliente.save
format.json { render :show, status: :created }
else
format.json { render json: @cliente.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @cliente.update(cliente_params)
format.json { render :show, status: :ok }
else
format.json { render json: @cliente.errors, status: :unprocessable_entity }
end
end
end
def destroy
@cliente.destroy
respond_to do |format|
format.json {head :no_content}
end
end
private
def cliente_params
params.permit(:CliERP, :CliRazao, :CliCNPJ, :CliEmail, :CliObs,
enderecos_attributes: [:EndTipo, :EndLogradouro, :EndNumero, :EndBairro, :EndCidade, :EndCEP, :EndEstado],
telefones_attributes: [:TelTipo, :TelNumero],
emails_attributes: [:MailTipo, :MailEndereco])
end
end
編輯:這裏是我的模型
cliente.rb
class Cliente < ActiveRecord::Base
has_many :enderecos, autosave: true
has_many :telefones, autosave: true
has_many :emails, autosave: true
has_many :pedido
accepts_nested_attributes_for :enderecos
accepts_nested_attributes_for :telefones
accepts_nested_attributes_for :emails
end
endereco.rb
class Endereco < ActiveRecord::Base
belongs_to :cliente
end
email.rb
class Email < ActiveRecord::Base
belongs_to :cliente
end
telefone.rb
class Telefone < ActiveRecord::Base
belongs_to :cliente
end
我認爲我的問題是client_params 謝謝!