34
loading...
This website collects cookies to deliver better user experience
rails new application-name --api
static getPatterns(){
fetch(pattern_url)
.then(resp => resp.json())
.then(patterns => {
for(const pattern of patterns){
let p = new Pattern(pattern)
p.appendPattern()
}
})
}
constructor({name, difficulty, description, yarn, category_id}){
...
}
static createPattern(){
const newP = {
name: document.getElementById("name").value,
difficulty: document.getElementById("difficulty").value,
description: document.getElementById("description").value,
yarn: document.getElementById("yarn").value,
category_id: document.getElementById("pattern-dropdown").value
}
const configObj = {
method: "POST",
headers:{
"Content-Type": "application/json"
},
body: JSON.stringify(newP)
}
fetch(pattern_url, configObj)
.then(resp => resp.json())
.then(pattern => {
const p = new Pattern(pattern)
p.appendPattern()
})