【发布时间】:2014-12-26 00:35:37
【问题描述】:
Rails 4. PSQL 9.3。托管在 Heroku 上。我用 angularJS 发送我的数组。
在我的 heroku 服务器上,我检查了我的日志,并且确实将参数作为数组发送。我也可以确认它正在路由到正确的update 路由。这是heroku日志:
INFO -- : Parameters: {"profile"=>{"order"=>[0, 1, 2, 3, 4]}, "id"=>"123"}
尽管正确发送参数,Rails 不会将这个数组保存在我的活动记录中。为什么?
整数数组是通过db migration添加的
add_column :profiles, :order, :integer, array: true
我的更新路线是这样的:
def update
@profile = Profile.find(params[:id])
if @profile.update(profile_params)
render json: @profile
else
render 'failed to update'
end
end
我将 profile_params 定义为:
def profile_params
params.require(:profile).permit(...some other variables, :order)
end
所有非常标准的东西,所以我不知道我做错了什么
在前端使用 angularJS 我有以下内容:
var params = {
profile:{
order: [0,1,2,4]
}
}
$http.put("http://my_server_url/123", params)
.success(function(data,status,headers,config){
console.log(data)
})
知道我在这里做错了什么吗?
编辑:找出问题所在,仍然需要帮助
所以在做了一些测试后,我发现当我检查 profile_params 时,它是空的。为什么发送数组时是空的?
【问题讨论】:
标签: ruby-on-rails arrays angularjs postgresql activerecord