Ruby on rails 允许当前用户只查看为其创建的用户
我如何允许当前用户只看到为他创建的用户? 当我创建一个用户时,我在新用户中添加了一个父id,我需要只显示在index.html.erb中创建的用户Ruby on rails 允许当前用户只查看为其创建的用户,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,我如何允许当前用户只看到为他创建的用户? 当我创建一个用户时,我在新用户中添加了一个父id,我需要只显示在index.html.erb中创建的用户 <table class="table table-striped custab"> <thead> <tr> <th>Email</th> <th>User Father</th> </tr> </t
<table class="table table-striped custab">
<thead>
<tr>
<th>Email</th>
<th>User Father</th>
</tr>
</thead>
<tbody>
<% if current_user.father_id.present? %> // WRONG LOGIG!
<% @users.each do |user| %>
<tr>
<td><%= user.email %></td>
<td><%= user.father_id %></td>
</tr>
<% end %>
<% else %>
<p>No one user created</p>
<% end %>
</tbody>
</table>
电子邮件
用户父亲
//登录错误!
没有创建任何用户
现在,我可以看到所有内容,但我只需要显示为当前用户创建的。我怎么能做到
def index
@users = User.where(father_id: current_user.id)
end
抱歉,答案在用户\控制器上 还有其他的吗?当用户没有创建其他用户时,协同原则是什么?您应该接受正确的答案。:-)