This is most likely a typo somewhere, and if it is, I apologize, but I can't seem to find where. I send a POST fetch to "http://localhost3006/players/update_or_create" and I have it properly formatted in my routes.rb file like so...
Rails.application.routes.draw do
post 'players/update_or_create', to: 'players#update_or_create'
end
But the fetch fails, I'm assuming because it cannot find the route that is clearly defined (controllers are also properly set up) The file where I call the dispatch looks as so...
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})
})
}
}
CodePudding user response:
You are missing a column (:
) after http://localhost
. It's a DNS issue not a rails router one.
This:
//DOMAIN() will return "http://localhost3006"
Has to return this:
//DOMAIN() will return "http://localhost:3006"