Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4024722
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:45:24+00:00 2026-05-20T10:45:24+00:00

How can I get this query to work where it goes through the checks

  • 0

How can I get this query to work where it goes through the checks before adding it to the posts array? I receive the following error “can’t convert Post into Array”. I’m assuming there may be a better way to query this but I am unsure of how to do so.

This is in in the user model and I am calling this in my home_controller as current_user.personal_feed and then attempting to display each result.

Also, I am not having any problem querying the posts by the users “friends” just having issues only adding the posts that pass certain parameters. Such as they must have a /slashtag in them and the user must also subscribe to that 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

I have changed the code to this.

  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

end

It does not raise any errors but it does not run the posts through my conditions. Every post by the users friends is still being displayed even though they do not subscribe to that individual subscription.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:45:25+00:00Added an answer on May 20, 2026 at 10:45 am
    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
    

    Find the current user, then loop over their friends, only add them to an array if xyz.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this error: Can't locate Foo.pm in @INC Is there an easier way
We get this error in Visual Studio 2005 and TFS very often. Can anyone
Why can't you do this and is there are work around? You get this
So this seems pretty basic but I can't get it to work. I have
This sounds dumb, but I can't get it to work. I think i just
How would I get something like this to work so that I can dynamically
I can get the element like this $(#txtEmail) but I'm not sure how to
This shouldn't be so hard but I just can't seem to get this to
Ok, if I have this right, my code can get cookies at a specific
I think this must be simple but I can't get it right... I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.