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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:48:29+00:00 2026-06-18T07:48:29+00:00

I am developing a Rails 3.2 application and want the user to be redirect

  • 0

I am developing a Rails 3.2 application and want the user to be redirect to a custom error page at errors#index when he tries to find a non-existing db record.

This is my code to do this inside the application controller:

if Rails.env.production?
  rescue_from Exception, with: :display_error
  rescue_from ActiveRecord::RecordNotFound, with: :display_error
end

private
def display_error
  render "errors/index", status: 404
end

This actually works fine in production mode. Now the question is, how do I test it beforehand? I have tried this:

it "leads to error page on unknown db record" do
  Rails.stub(:env).and_return("production")

  # Sign in
  @valid_user = FactoryGirl.create(:valid_user)
  visit new_user_session_path
  fill_in "Email", with: @valid_user.email
  fill_in "Password", with: @valid_user.password
  click_button "Sign in"

  # Trigger exception
  visit physician_path id: "this is not an id"
  assert_contain "You blew it!"
end

However, this leaves me with two errors:

  • undefined method 'development?' for "production":String on visit new_user_session_path
  • Couldn't find Physician with id=this is not an id on visit physician_path id: "this is not an id"

The first one seems to imply an error with mocking the production environment; the second one will hopefully go away once I have implemented the actual code.

How can I solve these two errors? Thanks!

  • 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-18T07:48:31+00:00Added an answer on June 18, 2026 at 7:48 am

    It looks like Rails.env stores an ActiveSupport::StringEnquirer rather than a plain string: https://github.com/rails/rails/blob/3096629d297a77a9b64747a0ac2df6b2cbf47a68/railties/lib/rails.rb#L81

    It might be easier to just stub the production? method:

    Rails.env.stub(:production?).and_return(true)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a Ruby on Rails application that needs to allow the user to
I'm developing a Rails application that has a background process that updates some user
I'm developing an application with Ruby on Rails that I want to maintain for
I am developing a Rails 3 application from which I want to be able
I'm developing a Rails 3 application that has two user types: Teacher and Company.
I'm developing a Rails 3 application that has two user types: Teacher and Company.
I'm developing my first rails application and I've met a necessity to check user
Hi I'm developing a Rails application that exposes some methods via ActiveResource. I want
I'm now developing a rails application. For localisation. I want to use an approach
I am developing a rails application in which I have two models User and

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.