I sometimes want to delegate by using method_missing
Rails で Web API を作っているとする。
こんな例をかんがえてみよう。
「ランキング」という機能がある。
ランキングを表すテーブル・モデルがある
カラムは type, title, start_at, end_at, ...
ranking has_many scores
API は rankings/{id}
レスポンスボディはこんな感じとする
code:json
{
"type": "exam",
"title": "第1回Rubyオープン模試",
"my_rank": 3,
"start_at": "2020-07-03T10:00:00+0900",
"end_at": "2020-07-10T10:00:00+0900",
"scores": [
{ "user_name": "ujihisa", "score": 100, "rank": 1 },
{ "user_name": "ujm", "score": 100, "rank": 1 },
{ "user_name": "qsona", "score": 13, "rank": 3 }
]
}
これをどのように実装する?