こんにちは。
今日もだらだらと技術をテキトーにつまんでは食いつまんでは食いしております。
enchant.jsをまあ大体習熟した(飽きたともいう)ので
今更ながらruby on rails をやりだしました。下記を参考に。
4. scaffoldを利用した開発(1) | TECHSCORE(テックスコア)
おりゃー、scaffold!(足場!)
これはすごい。
さてどんなコードが出力されるのかな?
#Controllerね。
def index
@items = Item.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @items }
end
end
はてなんじゃこりゃ。。。(´・ω・`)
respond_to do |format| とはなんぞや。。。
と思って調べたらすぐ理解できた。
do使用のサンプルコード。
["aaa ","bbb "].each do |x|
p x # aaa bbb と表示される
end
forで書き換える。
for x in ["aaa ","bbb "]
print x
end
だから多分respond_toってメソッドの結果が順にformatに入って
do〜endのブロックで実行されるのね。なるほどね。
で
Rails: How does the respond_to block work? - Stack Overflow
respond_to is a Rails helper method that is attached to the Controller class (or rather, its super class).
It is referencing the response that will be sent to the View (which is going to the browser).
だからdo〜endでViewに送られる何かに処理を行ってるんだろう。
その辺はおいおい理解する。