換句話說,在我的應用程序中,我有一個索引,顯示我希望從此列表中排除current_user的總用戶數。如何從所有用戶的索引中刪除current_user?
我已經使用以下代碼來防止user.name和從成功展示user.profile_photo:
<% unless user.hidden_for?(current_user) || user.blocked_for?(current_user) || user == current_user %>
但是,它仍然表示,顯示2個時用戶只顯示其他用戶的個人資料照片和姓名,它應該只說一個顯示用戶不包括我在那裏。
這裏是代碼行,最終需要修復:
<h4 class="events_counter">
<%= @users.any? ? "Showing #{pluralize(@users.size, 'people')}" : "No users to show" %>
</h4>
任何幫助將是真棒! 乾杯!
更新:(這裏是當前相關的索引操作)
class ProfilesController < ApplicationController
before_filter :authenticate_user!
def index
if params[:search]
terms = params[:search][:terms] || nil
min_age = params[:search][:age_min] || nil
max_age = params[:search][:age_max] || nil
zipcode = params[:search][:zipcode] || nil
distance = params[:search][:distance] || nil
education_id = params[:search][:education_id] || nil
# @ethnicity_id = params[:search][:ethnicity_id] || nil
ethnicity_ids = params[:search][:cat_ids].split('').uniq || nil
gender = params[:search][:gender] || nil
@users = User.active.scoped_by_search(terms, min_age, max_age, education_id, ethnicity_ids, gender)
else
@users = User.active.page params[:page]
end
end
@ user3399101感謝分享'索引'行動。我已經相應地更新了答案。讓我知道這是否有效。 –
就是這樣,謝謝! – user3399101
很高興幫助:) –