· 1 min read

Screencast: RABL - Ruby API Builder Language

Downloads in verschiedenen Formaten:

mp4 mp4 webm ogg

Resourcen:

Gemfile

[ruby] gem ‘rabl’ [/ruby]

config/initializers/rabl_config.rb

[ruby] Rabl.configure do |config| config.include_json_root = false end [/ruby]

app/views/articles/show.json.rabl

[javascript] object @article attributes :id, :name, :published_at

if current_user.admin? node(:edit_url) { |article| edit_article_url(article) } end

child :author do attributes :id, :name node(:url) { |author| author_url(author) } end

child :comments do attributes :id, :name, :content end [/javascript]

app/views/articles/index.json.rabl

[javascript] collection @articles

extends “articles/show” [/javascript]

app/views/articles/index.html.erb

[html] <div id=“articles” data-articles=”<%= render(template: “articles/index.json.rabl”) %>”> [/html]

Back to Blog