這很可能是某個地方的拼寫錯誤,如果是,我深表歉意,但我似乎找不到在哪里。我將 POST fetch 發送到“http://localhost3006/players/update_or_create”,并在我的 routes.rb 檔案中正確格式化了它,就像這樣......
Rails.application.routes.draw do
post 'players/update_or_create', to: 'players#update_or_create'
end
但是獲取失敗,我假設是因為它找不到明確定義的路由(控制器也正確設定)我呼叫調度的檔案看起來如此......
import DOMAIN from "../constants/domain"
//DOMAIN() will return "http://localhost3006"
// This is imported by AttributeSelection.js
export default function completeAttributeSelection(playerObj){
const playerPOST = ({
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: JSON.stringify({
atk: playerObj.atk,
sAtk: playerObj.sAtk,
def: playerObj.def,
sDef: playerObj.sDef,
spd: playerObj.spd,
hp: playerObj.hp,
name: playerObj.name
})
})
return (dispatch) => {
dispatch({type: "LOADING"})
console.log("Domain: " DOMAIN())
fetch((DOMAIN() "/players/update_or_create"), playerPOST)
.then(resp => resp.json())
.then(json => {
console.log(json)
dispatch({type: "ATTRIBUTE_UPDATE_COMPLETE", payload: json})
})
}
}
uj5u.com熱心網友回復:
:之后缺少一列 ( ) http://localhost。這是 DNS 問題,而不是 Rails 路由器問題。
這個:
//DOMAIN() will return "http://localhost3006"
必須回傳這個:
//DOMAIN() will return "http://localhost:3006"
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/350225.html
上一篇:在Ruby中將哈希作為引數傳遞
下一篇:十進制最大值的驗證未正確激活
