You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
![Exposing an API in Rails 3](https://cdn-ak-scissors.b.st-hatena.com/image/square/3bee82c7f10f49ac6c52299be9b4859b1ed55b29/height=288;version=1;width=512/https%3A%2F%2Fgithub.githubassets.com%2Fimages%2Fmodules%2Fgists%2Fgist-og-image.png)
コントローラでJSONレスポンスを定義する場合、 class EntriesController < ApplicationController respond_to :json def index @entries = Entry.all respond_with @entries.to_json(:only => :title, :body, :include => { :user => { :only => :name }, :comment => { :only => :name }, :image => { :only => :file } }) end end などと、to_jsonまたはas_jsonで:onlyや:includeオプションを使ってフィールドを指定できます。ただ、これでは冗長だし、より複雑な構造のレスポンスを定義するとなると面倒です。そこで、簡潔に複雑な構造を
Convert between XML, Hash, YAML, JSON in Ruby - Conversion Cheat Sheet Here's a little XML/JSON/YAML/Hashconversioncheat sheet for Ruby: First, let's create an XML document: require 'rubygems' require 'nokogiri' builder = Nokogiri::XML::Builder.new do |xml| xml.root { xml.products { xml.widget { xml.id_ "10" xml.name "Awesome widget" } } } end my_xml = builder.to_xml require 'active_support' #if y
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く