Skip to content

Commit aebb559

Browse files
committed
added better default results
1 parent d38afac commit aebb559

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
class LandingController < ApplicationController
22
def index
3-
@todo_item = TodoItem.first
3+
@todo_items = [
4+
TodoItem.new(name: "One item", due_at: 1.hour.from_now),
5+
TodoItem.new(name: "A second item", due_at: 2.hour.from_now),
6+
TodoItem.first
7+
]
8+
9+
@todo_item = TodoItem.new(name: "Foobar", due_at: 1.hour.from_now)
410
end
5-
end
11+
end

app/helpers/vue_ssr_helper.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ def render_single(component_name, data_hash)
1212
}
1313
}
1414

15-
response = HTTParty.post(ssr_server_url, body: body.to_json, headers: {"Content-Type" => 'application/json'})
15+
response = ::HTTParty.post(ssr_server_url, body: body.to_json, headers: {"Content-Type" => 'application/json'})
1616

17-
return JSON.parse(response.body).dig("results","content","html")
17+
return ::JSON.parse(response.body).dig("results","content","html")
1818
end
1919

2020
def render_many(component_name, payloads=[])
21-
2221
# hypernova has an odd payload format, so we need to make the keys to the hash
2322
# 0: {}, 1: {}, 2: {} # etc
2423

@@ -31,27 +30,27 @@ def render_many(component_name, payloads=[])
3130
}
3231
end
3332

34-
response = HTTParty.post(ssr_server_url, body: body_h.to_json, headers: {"Content-Type" => 'application/json'})
33+
response = ::HTTParty.post(ssr_server_url, body: body_h.to_json, headers: {"Content-Type" => 'application/json'})
3534

36-
return JSON.parse(response.body)["results"].map{|k,v| v["html"]}
35+
return ::JSON.parse(response.body)["results"].map{|k,v| v["html"]}
3736
end
3837

3938
def render_multiple_todo_items(todo_items)
40-
item_hashes = todo_items.map { |item| TodoItemSerializer.new(item).to_h }
39+
item_hashes = todo_items.map { |item| ::TodoItemSerializer.new(item).to_h }
4140

4241
raw render_many('TodoItem', item_hashes).join("\n")
4342
end
4443

4544
def render_single_todo_item(todo_item)
46-
raw render_single('TodoItem', TodoItemSerializer.new(todo_item).to_h )
45+
raw render_single('TodoItem', ::TodoItemSerializer.new(todo_item).to_h )
4746
end
4847

4948
# to speed up SSR we should do this.
5049
def cached_todo_item(todo_item)
5150
key = "vuessr::todo_item::#{todo_item.cache_key}"
5251
puts "key-> #{key}"
5352

54-
Rails.cache.fetch(key, expires_in: 10.seconds) do
53+
::Rails.cache.fetch(key, expires_in: 10.seconds) do
5554
render_single_todo_item(todo_item)
5655
end
5756
end

app/views/landing/index.html.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11

2+
<strong><h1>Render one</h1></strong>
23
<%= render_single_todo_item(@todo_item) %>
4+
5+
<strong><h1>Render many</h1></strong>
6+
7+
<%= render_multiple_todo_items(@todo_items) %>

0 commit comments

Comments
 (0)