「@」の扱い方について教えてください。
この場面では
<%= link_to(user.name, "/users/#{user.id}") %>の#{user.id}はなぜ@userではないのでしょうか??
予想では、アクションで@usersが定義され、「user」という値は@usersの中に含まれているから、なのかな??(曖昧)と思ったのですがいかがでしょうか?
<div class="main users-index"> <div class="container"> <h1 class="users-heading">ユーザー一覧</h1> <% @users.each do |user| %> <div class="users-index-item"> <!-- ⇓ここです--> <%= link_to(user.name, "/users/#{user.id}") %> </div> <% end %> </div> </div>
class UsersController < ApplicationController def index @users = User.all end end
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/18 06:43