· 1 min read
Screencast: JSON Dokumente mit Jbuilder erstellen
Downloads in verschiedenen Formaten:
Resourcen:
Gemfile
[ruby] gem ‘jbuilder’ [/ruby]
views/articles/show.json.builder
[ruby] json.(@article, :id, :name, :published_at) json.edit_url edit_article_url(@article) if current_user.admin?
json.author @article.author, :id, :name # or json.author do |json| json.(@article.author, :id, :name) json.url author_url(@article.author) end
json.comments @article.comments, :id, :name, :content # or json.comments @article.comments do |json, comment| json.partial! comment end [/ruby]
views/comments/_comment.json.jbuilder
[ruby] json.(comment, :id, :name, :content) [/ruby]