1

私は次のエラーを受信したコントローラ内部の私の方法のアップデートでは、強力なパラメータのレール4とangularjs中に問題がある:方法の更新とエラーunpermitedパラメータレール4

許可されていないパラメータ:ID、cliente_id、created_atとし、 ID: 不許可パラメータupdated_atのID、cliente_id、のcreated_at、:ID、​​cliente_id、のcreated_at、 不許可パラメータupdated_atの:ID、cliente_id、のcreated_at、 不許可パラメータupdated_atの 不許可パラメータupdated_atのID、cliente_id、のcreated_at: 不許可パラメータupdated_atの、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"=>"financeiro[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 

編集:ここに私のモデルのがあります

クライアントe.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に のおかげであると思います!

答えて

関連する問題