· 1 min read

Screencast: Das Rails API Gem

Downloads in verschiedenen Formaten:

mp4 m4v webm ogg

Resourcen:

terminal

[bash] gem install rails-api rbenv rehash rails-api new todo rails g scaffold task name rake middleware diff api_middleware.txt full_middleware.txt [/bash]

tasks_controller.rb

[ruby] include ActionController::MimeResponds include ActionController::Helpers include ActionController::Cookies include ActionController::ImplicitRender

# GET /tasks # GET /tasks.json def index @tasks = Task.all

# respond_to do |format| # format.json { render } # format.xml { render xml: @tasks } # end end [/ruby]

views/tasks/index.json.rabl

[javascript] collection @tasks attributes :id, :name [/javascript]

config/application.rb

[ruby] config.middleware.insert_after ActiveRecord::QueryCache, ActionDispatch::Cookies [/ruby]

Back to Blog