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

  • Home
  • SEARCH
  • 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 8851219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:06:06+00:00 2026-06-14T13:06:06+00:00

It’s giving me a hard time to debug this. It was working perfectly before

  • 0

It’s giving me a hard time to debug this. It was working perfectly before I moved to PostgreSQL from SQLite3. What’s strange to me is that there’s another controller that has almost the same code as this, and that page works fine. Could anyone help me?

Error:

ActiveRecord::StatementInvalid in Good_posts#index

Showing c:/ruby/mangfeel/app/views/good_posts/index.html.erb where line #3 raised:

PG::Error: ERROR:  syntax error at or near "desc"
LINE 1: ...  "good_posts".* FROM "good_posts"  ORDER BY like desc LIMIT...
                                                         ^
: SELECT  "good_posts".* FROM "good_posts"  ORDER BY like desc LIMIT 15 OFFSET 0

good_posts_controller that’s causing the problem:

def index
 @good_posts = GoodPost.paginate(:page => params[:page], order: 'like desc', per_page: 15)
 @good_client_ip = request.remote_ip.encode! 'utf-8'

 respond_to do |format|
  format.html # index.html.erb
  format.json { render json: @good_posts }
 end
end

post_controller, which has similar code but works fine:

def index
 @posts = Post.paginate(:page => params[:page], order: 'created_at desc', per_page: 15)
 @client_ip = request.remote_ip.encode! 'utf-8'

 respond_to do |format|
  format.html # index.html.erb
  format.json { render json: @posts }
 end
end

I appreciate all the help!

  • 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-06-14T13:06:07+00:00Added an answer on June 14, 2026 at 1:06 pm

    LIKE is an operator so you can’t use it as a column name unless you double quote it:

    @good_posts = GoodPost.paginate(... order: '"like" desc' ...)
    

    Whenever ActiveRecord generates a column name in some SQL it will quote the column name for you; so .where(:like => 11) will be sent to the database as where "like" = 11 and everyone is happy. When you write the column name in an SQL snippet (such as .where('"like" = ?', 11)) you’ll have to double quote it to distinguish it from the pattern matching operator. You’ll be happier if you rename the column to something (such as likes or number_of_likes) that doesn’t conflict with a keyword

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.