足場を使用して、投稿用のCRUDシステムを作成しました。コントローラーでは、次のように表示されます。
class PostsController < ApplicationController
# GET /posts
# GET /posts.json
def index
@posts = Post.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @posts }
end
end
それは何で
respond_to、どこから来たのですか?演算子を使用しているので、doある種の反復可能なリストだと思います。formatそのリストのそれぞれで、メソッドhtmlとjsonメソッドを実行します。メソッド
{ render json: @posts }に関連してどのように機能しますか?メソッドへの引数として渡されていますかjson?とそれぞれがオブジェクトですかrender json: @posts?記号の外で使用されるコロン表記を見たことがありません。renderjson