【问题标题】:How would I get all people, that are following my in Ruby我怎样才能让所有在 Ruby 中关注我的人
【发布时间】:2019-12-15 11:54:47
【问题描述】:

我正在使用 act_as_follower gem,我得到了我关注的所有用户,但现在我想要所有关注我的用户,我该怎么做。我检查了一下,我认为是这样的 current_user.followers,但我无法让它工作。我关注的人的代码是这样的:

<% @users = User.all %>
<% @users.each do |user| %>
    <% unless user == current_user %>
        <div class="container people-lists list-following">
            <%= image_tag("/assets/" +  user.avatar + ".png",  alt: "Logo", class: "people-image") %>
            <%= user.username %>
            <% if user_signed_in? %>
                <% unless user == current_user %>
                    <% if current_user.following?(user) %>
                        <%= button_to("Un-Follow", user_follow_path(user.to_param, current_user.get_follow(user).id), :method => :delete, :remote => true, class: 'btn btn-primary button') %>
                    <% else %>
                        <%= button_to("Follow", user_follows_path(user.to_param), :remote => true, class: 'btn btn-primary button') %>
                    <% end %>
                <% end %>
            <% end %>
        </div>
    <% end %>
<% end %>

【问题讨论】:

    标签: ruby


    【解决方案1】:

    我发现我 User.all 返回了所有这些,我可以使用 all_following,并像这样跟随它。

    <% @users = current_user.all_following %>
    

    像这样

    <% @users = current_user.followers %>
    

    【讨论】:

      猜你喜欢
      • 2013-09-05
      • 1970-01-01
      • 2013-02-22
      • 1970-01-01
      • 2011-08-09
      • 1970-01-01
      • 1970-01-01
      • 2021-05-27
      • 2017-09-07
      相关资源
      最近更新 更多