问题描述
Rails 版本:5
我想从前端向 rails 发布一个名为 urls
的新项目。
export function printPosts(params) {
const endpoint = `v1/posts/print`
return http.post(endpoint,params).then(({ data }) => data)
}
但是在 post
对象中,没有命名为 urls
的项目。
像 id
、title
、body
、url
之类的东西。
当我发布到这个端点时,日志显示
<ActionController::Parameters {"urls"=>"https://www.example.com/post/url/1\nhttps://www.example.com/post/url/2","format"=>:json,"controller"=>"v1/posts","action"=>"print","post"=>{}} permitted: false>
undefined method `strip' for 1:Integer
permitted: false
可能意味着 urls
不允许发送。
我将它添加到 rails 的 app/controllers/v1/posts_controller.rb
控制器
private
def post_params
params.permit(
:urls
)
end
然后打印它的值:
def print
p post_params.to_h.symbolize_keys
end
<ActionController::Parameters {"urls"=>"https://www.example.com/post/url/1\nhttps://www.example.com/post/url/2","post"=>{}} permitted: false>
Unpermitted parameters: :format,:post
{:urls=>"https://www.example.com/post/url/1\nhttps://www.example.com/post/url/2"}
undefined method `strip' for 1:Integer
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)