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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:17:52+00:00 2026-05-24T00:17:52+00:00

I am learning Rails with railstutorial.org, and I am confused about something: in this

  • 0

I am learning Rails with railstutorial.org, and I am confused about something:
in this chapter the author tells us to do some testing in the console with the respond_to? method on a User object, and it works ok. But later, when we write the test for the :encrypted_password attribute, he uses respond_to.

Out of curiosity, I tried respond_to in the console, for a User object, and I get an error saying the method doesnt exist. Alas, if I try to write the test using respond_to? instead of respond_to, the test doesnt run.

Could someone explain me the difference, and why does the test only run with respond_to?

  • 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-24T00:17:52+00:00Added an answer on May 24, 2026 at 12:17 am

    Ruby treats ? and ! as actual characters in a method name. respond_to and respond_to? are different. ? indicates that this should respond with a true or false (by convention; this is not a requirement). Specifically:

    respond_to? is a Ruby method for detecting whether the class has a particular method on it. For example,

    @user.respond_to?('eat_food')
    

    would return true if the User class has an eat_food method on it.

    respond_to is a Rails method for responding to particular request types. For example:

    def index
      @people = Person.find(:all)
    
      respond_to do |format|
        format.html
        format.xml { render :xml => @people.to_xml }
      end
    end
    

    However, in the RailsTutorial link you’ve provided, you’re seeing an RSpec method should interacting with RSpec’s respond_to method. This wouldn’t be available in your console, unless you run rails console test.

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

Sidebar

Related Questions

I am learning ruby from this guide http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec:deploying , and I am trying to
I am learning rais from the rails tutorial book: http://ruby.railstutorial.org/chapters/sign-in-sign-out#fnref:9.14 I am working on
I'm learning ruby on rails by following the tutorials in http://ruby.railstutorial.org/ . I'm getting
I'm new to Rails and i'm currently learning from tutorials from http://ruby.railstutorial.org/chapters/modeling-and-viewing-users-one#top find_by_email works
I have been use the rails console for testing and learning purposes and when
I have been interested in learning Rails for some time now and feel now
This is a beginner's rails learning confusion. When I learn rails, from time to
I am learning Ruby on Rails so I'm sure I'll find this out sooner
I'm learning Ruby on Rails. I'm using some associations (has_many :through, ...) But i'm
Learning rails and something smells a little funny. I have the following form for

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.