【发布时间】:2017-06-02 15:49:14
【问题描述】:
我正在构建一个 API 端点来更新模型。我可以更新除嵌套资源之外的每一列,我尝试了不同的方法,但似乎没有任何效果
这是我要发送到服务器的 JSON
{
"reservation": {
"reservation_dates": [
{
"is_desirable": true,
"date": "5-10-2019"
}
]
}
}
我从 reservation_date 获得了一个 unpermitted_param,尽管我已将其添加到我的
def permitted_attributes_for_update
params.require(:reservation).permit(:date, :time, :comment, :budget, :currency, :status,
:general_text, :idea_text, :artist_text, :desired_city,
:desired_country, :desired_googleid, :studio_id, :artist_id,
:tattoos, reservation_dates: [], general_url_array: [],idea_url_array: [],
artist_url_array: [])
end
我希望能够直接从 JSON 更新,或者至少允许该数组,以便稍后在我的 UpdateService 上使用
感谢您的帮助
【问题讨论】:
-
用确切的错误更新问题。
-
模型中是否允许嵌套属性?
-
我有@8bithero
标签: ruby-on-rails json api ruby-on-rails-5