Help us understand the problem. What is going on with this article?

link_to の引数と展開の違いまとめ

More than 5 years have passed since last update.


▼基本 コントローラやアクション、IDなど予約パラメータやルート定義にあるものはURLに含まれる
<%= link_to "TEST1-1", controller:"product", action:"edit" %>
<%= link_to "TEST1-2", controller:"product", action:"edit", id: 1 %>

<a href="/product/edit">TEST1-1</a>
<a href="/product/edit/1">TEST1-2</a>

<%= link_to "TEST2-1",{controller:"product", action:"edit"}, id:"title" %>
<%= link_to "TEST2-2",{controller:"product", action:"edit", id:3}, id:"title" %>

<a href="/product/edit" id="title">TEST2-1</a>
<a href="/product/edit/3" id="title">TEST2-2</a>

<%= link_to "TEST2-3",{controller:"product", action:"edit",id:3, book_author:"Bob"}, id:"title" %>

<a href="/product/edit/3?book_author=Bob" id="title">TEST2-3</a>


<%= link_to "TEST3",{controller:"product", action:"edit"}, {id:"title", class:"top"} %>

<a href="/product/edit" id="title">TEST3</a>

<%= link_to "TEST4",{controller: "product", action: "edit"}, {id: 1, class: "top"},{width: 100, height: 200} %>

<a href="/product/edit" class="top" id="1">TEST4</a>

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away