Ruby on rails 如何筛选这些帖子,然后将它们重新添加到列表中?

Ruby on rails 如何筛选这些帖子,然后将它们重新添加到列表中?,ruby-on-rails,Ruby On Rails,在将此查询添加到posts数组之前,如何使其通过检查才能工作?我收到以下错误“无法将Post转换为数组”。我想可能有更好的方法来质疑这一点,但我不确定如何做到这一点 这是在用户模型中,我在我的家庭控制器中将其称为当前用户个人订阅源,然后尝试显示每个结果 此外,我没有任何问题查询用户“朋友”的帖子,只是添加通过某些参数的帖子有问题。例如,它们必须具有/slashtag,并且用户还必须订阅该slashtag def personal_feed posts = [] # cyc

在将此查询添加到posts数组之前,如何使其通过检查才能工作?我收到以下错误“无法将Post转换为数组”。我想可能有更好的方法来质疑这一点,但我不确定如何做到这一点

这是在用户模型中,我在我的家庭控制器中将其称为当前用户个人订阅源,然后尝试显示每个结果

此外,我没有任何问题查询用户“朋友”的帖子,只是添加通过某些参数的帖子有问题。例如,它们必须具有/slashtag,并且用户还必须订阅该slashtag

def personal_feed
      posts = []
      # cycle through all posts (of the users "friends) & check if the user wants to see them
      Post.find(:all, :conditions => ["user_id in (?)", friends.map(&:id).push(self.id)], :order => "created_at desc").each do |post|
        # first checkpoint: does this post contain a /slashtag
        post.message.scan(%r{(?:^|\s+)/(\w+)}).map {|element|
          # second checkpoint: does this user subscribe to any of these slashtags?
          if self.subscriptions.find_by_friend_id_and_slashtag(post.user.id, element[0])
            posts += post
          end
        }
      end
    end
我已将代码更改为此

  def personal_feed
    posts = []
    # cycle through all posts (of the users "friends) & check if the user wants to see them
    Post.find(:all, :conditions => ["user_id in (?)", friends.map(&:id).push(self.id)], :order => "created_at desc").each do |post|
      # first checkpoint: does this post contain a /slashtag
      post.message.scan(%r{(?:^|\s+)/(\w+)}).map {|element|
        # second checkpoint: does this user subscribe to any of these slashtags?
          posts << post if self.subscriptions.find_by_friend_id_and_slashtag(post.user.id, element[0])
      }
    end
def个人订阅源
职位=[]
#循环浏览(用户的朋友)的所有帖子并检查用户是否希望看到它们
Post.find(:all,:conditions=>[“用户id在(?),”friends.map(&:id).push(self.id)],:order=>“在描述时创建”)。每个都要发布|
#第一个检查点:此帖子是否包含/slashtag
post.message.scan(%r{(?:^|\s+/(\w+)}).map{|
#第二个检查点:该用户是否订阅了这些slashtags?
发布
def个人订阅源
如果用户已登录?
@好朋友=[]
当前_user.friends.each do | f|
@好朋友
def个人订阅源
职位=[]
#循环浏览(用户的朋友)的所有帖子并检查用户是否希望看到它们
Post.find(:all,:conditions=>[“用户id在(?),”friends.map(&:id).push(self.id)],:order=>“在描述时创建”)。每个都要发布|
#第一个检查点:此帖子是否包含/slashtag
post.message.scan(%r{(?:^|\s+/(\w+)}).map{|
#第二个检查点:该用户是否订阅了这些slashtags?

我正在使用Desive的帖子。我将尝试使用这种方法。查看我在原始帖子中编辑的代码。为什么我的条件不起作用?即使我将条件更改为我知道不正确的内容,它也会添加每一篇帖子。posts+=post不起作用的原因是因为语法想要将两个数组添加在一起。但是posts是一个数组。所以,若要将post添加到post中,您将执行post谢谢。这不会产生错误,但我似乎无法让它在不同的条件下运行。
def personal_feed
    if user_signed_in?
      @good_friends = []
      current_user.friends.each do |f|
        @good_friends << f #if some condition here
      end 
    else
       #cannot find friends because there is not a current user.
       #might want to add the devise authenticate user before filter on this method
    end 
end
  def personal_feed
        posts = []
        # cycle through all posts (of the users "friends) & check if the user wants to see them
        Post.find(:all, :conditions => ["user_id in (?)", friends.map(&:id).push(self.id)], :order => "created_at desc").each do |post|
          # first checkpoint: does this post contain a /slashtag
          post.message.scan(%r{(?:^|\s+)/(\w+)}).map {|element|
            # second checkpoint: does this user subscribe to any of these slashtags?
            posts << post if self.subscriptions.find_by_friend_id_and_slashtag(post.user.id, element[0])
          }
        end
        posts = posts
  end