質問するログイン新規登録

回答編集履歴

1

リンクに

2020/09/05 06:49

投稿

unhappychoice
unhappychoice

スコア1531

answer CHANGED
@@ -1,9 +1,9 @@
1
1
  仕組みを知りたいのであれば、Rails のソースを検索、読むのが良いのかと思いました
2
2
 
3
3
  `def link_to` で調べると、 二番目の引数は `options` で `url_for(options)` によって URL に変換されていることがわかります。
4
- https://github.com/rails/rails/blob/60ef07093d9023568ccbbd34e862b40395ec02f4/actionview/lib/action_view/helpers/url_helper.rb#L196
4
+ [https://github.com/rails/rails/blob/60ef07093d9023568ccbbd34e862b40395ec02f4/actionview/lib/action_view/helpers/url_helper.rb#L196](https://github.com/rails/rails/blob/60ef07093d9023568ccbbd34e862b40395ec02f4/actionview/lib/action_view/helpers/url_helper.rb#L196)
5
5
 
6
6
  `def url_for` で調べると、 Model が渡された場合(最後の `else` 節) ` HelperMethodBuilder.url.handle_model_call self, options` によって URL を作っていることがわかります
7
- https://github.com/rails/rails/blob/de7f57f9482dd94c585cbd63cdef061b81371db3/actionpack/lib/action_dispatch/routing/url_for.rb#L171
7
+ [https://github.com/rails/rails/blob/de7f57f9482dd94c585cbd63cdef061b81371db3/actionpack/lib/action_dispatch/routing/url_for.rb#L171](https://github.com/rails/rails/blob/de7f57f9482dd94c585cbd63cdef061b81371db3/actionpack/lib/action_dispatch/routing/url_for.rb#L171)
8
8
 
9
9
  その先も知りたければ探していけばよいだけですが、つまりは Model => URL 文字列 の変換を行っていて、リンクが HTML として作られているため、という感じの説明になるかと思います