Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
render on the client - search controllers' views first
- Loading branch information
1 parent
0c9de8c
commit a12568e
Showing
4 changed files
with
20 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,5 @@ | ||
#get "posts", :format => 'ruby' | ||
download "/posts.json" do |s, a| | ||
@posts = JSON.new.parse(a.result) | ||
render :partial => "posts/posts", :update => "posts" | ||
@posts = JSON.parse(a.result) | ||
render :partial => "posts", :update => "posts" | ||
end | ||
|
||
#get "posts", :format => 'ruby' | ||
#render_posts :update => "posts" | ||
|
||
def render_posts(options = {}) | ||
id, posts = options[:update], @posts | ||
if @posts.empty? | ||
output = "No posts! Add one below!" | ||
else | ||
output = "<table>" | ||
output += " <tr>" | ||
posts.first.keys.each do |key| | ||
output += " <th>#{key}</th>" | ||
end | ||
output += " </tr>" | ||
posts.each do |post| | ||
output += " <tr>" | ||
post.keys.each do |key| | ||
output += " <td>#{post[key]}</td>" | ||
end | ||
output += " </tr>" | ||
end | ||
output += "</table>" | ||
end | ||
document.send(id)[:innerHTML] = output | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters