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 7017617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:56:13+00:00 2026-05-27T22:56:13+00:00

I am getting a 500 error when I try to deploy my app to

  • 0

I am getting a 500 error when I try to deploy my app to Heroku (it works fine on my localhost). Not sure why this is happening.

How can I fix it? Error details are below…

Error Details

2012-01-03T10:33:49+00:00 app[web.1]: Started GET "/" for 

2012-01-03T10:33:49+00:00 app[web.1]:   Processing by PagesController#home as HTML
2012-01-03T10:33:49+00:00 app[web.1]: 
2012-01-03T10:33:49+00:00 app[web.1]: Completed   in 15ms
2012-01-03T10:33:49+00:00 app[web.1]: 
2012-01-03T10:33:49+00:00 app[web.1]:   app/controllers/pages_controller.rb:7:in `home'
2012-01-03T10:33:49+00:00 app[web.1]: ActiveRecord::StatementInvalid (PGError: ERROR:      syntax error at or near "["
2012-01-03T10:33:49+00:00 app[web.1]: : SELECT     "posts".* FROM       "posts"  WHERE        (user_id IN ([]) OR user_id = 2) ORDER BY  posts.created_at DESC LIMIT 30 OFFSET 0):
2012-01-03T10:33:49+00:00 app[web.1]: 
2012-01-03T10:33:49+00:00 app[web.1]: LINE 1: ...sts".* FROM       "posts"  WHERE       (user_id IN ([]) OR use...
2012-01-03T10:33:49+00:00 app[web.1]:             

Pages Controller

class PagesController < ApplicationController

def home
  @title = "Home"
  if signed_in?
      @post = Post.new
      @feed_items = current_user.feed.paginate(:page => params[:page])
  end
end

User Model

class User < ActiveRecord::Base

has_many :posts, :dependent => :destroy

has_many :relationships, :foreign_key => "follower_id",
:dependent => :destroy
has_many :reverse_relationships, :foreign_key => "followed_id",
:class_name => "Relationship",
:dependent => :destroy

has_many :following, :through => :relationships, :source => :followed
has_many :followers, :through => :reverse_relationships, :source => :follower

attr_accessor :password
attr_accessible :name, :email, :password, :password_confirmation

email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

validates :name,     :presence => true,
                     :length => { :maximum => 50 }

validates :email,    :presence => true,
                     :format => { :with => email_regex },
                     :uniqueness => { :case_sensitive => false}

validates :password, :presence     => true,
                     :confirmation => true,
                     :length       => { :within => 6..40 }

before_save :encrypt_password

def has_password?(submitted_password)
    encrypted_password == encrypt(submitted_password)
end

def self.authenticate(email, submitted_password)
    user = find_by_email(email)
    return nil  if user.nil?
    return user if user.has_password?(submitted_password)
end

def self.authenticate_with_salt(id, cookie_salt)
    user = find_by_id(id)
    (user && user.salt == cookie_salt) ? user : nil
end

def following?(followed)
    relationships.find_by_followed_id(followed)
end

def follow!(followed)
    relationships.create!(:followed_id => followed.id)
end

def unfollow!(followed)
    relationships.find_by_followed_id(followed).destroy
end

def feed
    Post.from_users_followed_by(self)
end

private

def encrypt_password
    self.salt = make_salt unless has_password?(password)
    self.encrypted_password = encrypt(password)
end

def encrypt(string)
    secure_hash("#{salt}--#{string}")
end

def make_salt
    secure_hash("#{Time.now.utc}--#{password}")
end

def secure_hash(string)
    Digest::SHA2.hexdigest(string)
end

end

Post Model

class Post < ActiveRecord::Base
attr_accessible :content

belongs_to :user

validates :content, :presence => true, :length => { :maximum => 140 }
validates :user_id, :presence => true

default_scope :order => 'posts.created_at DESC'

scope :from_users_followed_by, lambda { |user| followed_by(user) }

def self.from_users_followed_by(user)
  following_ids = user.following_ids
  where("user_id IN (#{following_ids}) OR user_id = ?", user)
end

private

def self.followed_by(user)
  following_ids = %(SELECT followed_id FROM relationships
        WHERE follower_id = :user_id)
  where("user_id IN (#{following_ids}) OR user_id = :user_id",
       { :user_id => user })
end
end
  • 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-27T22:56:14+00:00Added an answer on May 27, 2026 at 10:56 pm

    Your problem is here:

    def self.from_users_followed_by(user)
      following_ids = user.following_ids
      where("user_id IN (#{following_ids}) OR user_id = ?", user)
      #------------------^^^^^^^^^^^^^^^^
    end
    

    Your following_ids will be an array and when you "#{array}", you get things like [] and [11, 23, 42]. So that where will end up looking like this:

    where("user_id IN ([]) OR user_id = ?", user)
    where("user_id IN ([11, 23, 42]) OR user_id = ?", user)
    

    neither of those contain valid SQL. Some databases might ignore the stray brackets but PostgreSQL will not.

    You need to make two changes:

    1. Don’t include the user_id IN (...) at all if following_ids is empty. Doing c in () isn’t valid SQL so you don’t want to do that. Again, some databases are lenient and forgiving, PostgreSQL is (thankfully) neither of those things.
    2. Don’t use simple string interpolation to supply values for your IN; for that matter, don’t use string interpolation for your SQL at all (unless there is absolutely no other way and that’s rare): we’re not writing PHP in 1999, we’re supposed to know better now. Lucky for you (and the rest of us), AR will do the Right Thing if you hand it an array for a placeholder value.

    Something like this should work better:

    def self.from_users_followed_by(user)
      following_ids = user.following_ids
      if(following_ids.empty?)
        where('user_id = ?', user)
      else
        where('user_id in (?) or user_id = ?', following_ids, user)
      end
    end
    

    You could also do it like this:

    def self.from_users_followed_by(user)
      following_ids = user.following_ids
      if(following_ids.empty?)
        where('user_id = ?', user)
      else
        following_ids.push(user.id)
        where('user_id in (?)', following_ids
      end
    end
    

    or, my favorite, like this:

    def self.from_users_followed_by(user)
      where('user_id in (?)', user.following_ids + [user.id])
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting a mysterious 500 error when i try to deploy my first
I've a rails 3.1 app on Heroku, I keep getting an 500 error in
Im getting 500 internal server error everytime I try access my admin or login
When I try to make a shape using variables, I keep getting this error
Getting this error: 2009-09-03 12:44:02.307 xcodebuild[307:10b] warning: compiler 'com.apple.compilers.llvm.clang.1_0.analyzer' is based on missing compiler
Getting a rendering error for this form: 'NoneType' object has no attribute 'widget' http://dpaste.com/88585/
Getting this error with jquery & jquery.form. Site has been live for awhile..upgraded to
I'm trying to get devise to login but I'm getting a 500 error due
I am getting the following error with my GAE application: 2011-06-25 00:15:59.023 /publish 500
I am trying to deploy a simple app to Heroku (Sinatra and using DataMapper

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.