【发布时间】:2017-07-26 05:46:48
【问题描述】:
我尝试使用此请求正文将我的 json 发布到 rails 服务器
{"post":{
"user_id": 2,
"title": "kehangatan di pagi hari",
"category": "kehangatan di pagi hari",
"imageposts": [{"imageurl":"DJAWHDAHWDKJHAW DHJAWDHAWDAWDAD"}],
"description":"<p>memang sange</p>"
} }
这是我的posts_params
def post_params
params.require(:post).permit(:title, :user_id, :description, :category, :imageposts => [:imageurl])
end
不幸的是,当我发布 ajax 帖子时,我的终端出现错误
#<ActiveRecord::AssociationTypeMismatch: Imagepost(#42287660) expected, got ActiveSupport::HashWithIndifferentAccess(#30074960)>
我已经在我的 imageposts 强参数上尝试了这个,但它也不起作用
imageposts: [:imageurl]
谁能解决这个问题...
【问题讨论】:
-
发布收到的
params(查看服务器日志)
标签: ruby-on-rails ruby activerecord active-model-serializers