Settings not loading from turbo.json
Closed this issue · 6 comments
aviderambo commented
dalezak commented
Hmm, your turbo.json
looks fine, try changing your print
lines to
print("path \(path)")
print("text \(text)")
And also add print("json \(json)")
inside the if let json
block, that should output the contents.
aviderambo commented
Weird, right?
This seems to be working. The request must be made from WK View for any reason?
func loadSettings() -> Dictionary<String, AnyObject> {
let path = turboPath("/turbo.json")
let url = URL(string: path)
let semaphore = DispatchSemaphore(value: 0)
var text: String = ""
let task = URLSession.shared.dataTask(with: url!) {(data, response, error) in
text = String(data: data!, encoding: String.Encoding.utf8)!
semaphore.signal()
}
task.resume()
semaphore.wait()
if let json = stringToDictionary(text: text) {
return (json["settings"] as? Dictionary<String, AnyObject>)!
}
return [:]
}
dalezak commented
Do you have @hotwired/turbo-rails
in your package.json
?
I just realized I forgot this in the instructions.
If you are using Yarn, do yarn add @hotwired/turbo-rails
.
If you are using NPM, do npm add @hotwired/turbo-rails
.
dalezak commented
Alright @codigodo, I tested out your changes and they seem to work well.
So I've updated loadSettings to use URLSession.shared.dataTask
instead.
Can you pull the latest to verify the changes still work for you?
aviderambo commented
Works great!
dalezak commented
Good news, closing issue.