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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:55:53+00:00 2026-05-28T04:55:53+00:00

I’m attempting to complete section 12.3 of the railstutorial.org tutorial. At the beginning of

  • 0

I’m attempting to complete section 12.3 of the railstutorial.org tutorial.

At the beginning of section 12.3, my rspec tests were passing and the site worked. However, after adding the listing in section listing 12.42, a large number of previously-passing tests started failing. (As part of my error checking, I tried copying and pasting the code directly from the tutorial site, with the same result.) I attempted to open the site on localhost, and found the tests were failing because the home page was returning an exception:

SQLite3::SQLException: no such column: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51: SELECT “microposts”.* FROM “microposts” WHERE (user_id IN ([2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51]) OR user_id = 1) ORDER BY microposts.created_at DESC LIMIT 30 OFFSET 0

Rails.root: /Users/paulbogard/Sites/sample_app

The code that seems to be generating that exception is in my app/models/micropost.rb:

class Micropost < ActiveRecord::Base
  attr_accessible :content

  belongs_to :user

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

  default_scope :order => 'microposts.created_at DESC'

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

Playing around with it, it seems like it doesn’t like the square brackets surrounding the array of following_ids. For example, changing the where line to this simplified magic number version also generates the “no such column” error:

where("user_id IN ([2, 3, 4]) OR user_id = ?", user)

But if I change it to the following, I don’t get the error:

where("user_id IN (2, 3, 4) OR user_id = ?", user)

And, in fact, using the no-square-bracket version has all tests passing except for the ones specifically checking that it’s returning posts from followed users and not returning posts from unfollowed users (as I’d expect by just tossing magic numbers into the SQL query).

So it appears the square brackets seem to be making SQLite think that what’s included is a column name. Is there a way to rewrite the following_ids = user.following_ids line so that I get a string of array values without square brackets? Or should I be doing something else entirely?

  • 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-28T04:55:53+00:00Added an answer on May 28, 2026 at 4:55 am

    Just let ActiveRecord include the array into your query. That way, it handles the formatting and even the eventual escaping.

    def self.from_users_followed_by(user)
      following_ids = user.following_ids
      where("user_id IN (?) OR user_id = ?", following_ids, user)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is

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.