Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS到Rails MassaSignmentSecurity::错误_Javascript_Ruby On Rails_Angularjs - Fatal编程技术网

Javascript AngularJS到Rails MassaSignmentSecurity::错误

Javascript AngularJS到Rails MassaSignmentSecurity::错误,javascript,ruby-on-rails,angularjs,Javascript,Ruby On Rails,Angularjs,在将AngularJS与Rails一起使用时,我在更新时不断收到MassaSignmentSecurity错误。我知道这是由于将“created_at”和“updated_at”等属性与数据一起传递所致 为了解决这个问题,我一直在构建一些json,它只传递表单中的属性。这确实在整个计划中创造了更多的维护 有更好的方法吗 以下是一个例子: 安格拉斯 $scope.contruct_json = -> { name: $scope.client.name s

在将AngularJS与Rails一起使用时,我在更新时不断收到MassaSignmentSecurity错误。我知道这是由于将“created_at”和“updated_at”等属性与数据一起传递所致

为了解决这个问题,我一直在构建一些json,它只传递表单中的属性。这确实在整个计划中创造了更多的维护

有更好的方法吗

以下是一个例子:

安格拉斯

  $scope.contruct_json = ->
    {
      name: $scope.client.name
      surname: $scope.client.surname
    }


  # --------------------------------------------------------------------------------
  # Update
  # --------------------------------------------------------------------------------
  $scope.update = ->
    Client.update
      id: $stateParams['id']
    ,
      client: $scope.contruct_json()
    , (response) ->
      $location.path "/clients/#{$stateParams['id']}"
更新

将我的AngularJS代码更改为

  # Remove keys from hash to make it acceptable for Rails to update
  $scope.remove_keys = (hash) ->
    new_hash = {}
    angular.forEach(hash, (value,key) ->
      if(key!='id' && key!='created_at' && key!='updated_at')
        new_hash[key]=value
    ,  new_hash)
    return new_hash
  # --------------------------------------------------------------------------------
  # Update
  # --------------------------------------------------------------------------------
  $scope.update = ->
    Client.update
      id: $stateParams['id']
    ,
      client: $scope.remove_keys($scope.client)
    , (response) ->
      $location.path "/clients/#{$stateParams['id']}"

也许你应该考虑在<代码>客户机< /代码>模型中的属性分配,使用<代码> TraceAccess < /C> >

< P>但是,你要分配你的属性,你需要在模型中声明它们为质量可分配的。请尝试以下操作:

class Client < ActiveRecord
    attr_accessible :created_at, :updated_at # Any attributes you need to make mass-assignable
end
class客户端
让所有属性都可以访问吗?一般来说,否:)我会对这些东西持悲观态度,只启用您直接需要的东西。另一种选择是在控制器中去掉这些属性,比如在过滤器之前的一些
或类似的东西中