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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:16:37+00:00 2026-05-19T15:16:37+00:00

Having read this: "No route matches" error? I’m trying to figure out if there

  • 0

Having read this:
"No route matches" error?

I’m trying to figure out if there is a gem or way to monkey patch actionpack to get around this constraint.

Basically, I’m writing specs (they run fast), and I don’t understand why actionpack throws this error when being applied to an object which isn’t “saved”.

For two reasons:

  1. Why is it throwing a “No route matches” when it really should be throwing something more meaningful (e.g. object must be saved before a route can be constructed, or object ID is nil). The exception seems a little obscure.
  2. I shouldn’t have to save the object at all if all I am trying to do is generate a url for that object, given the ID is populated using a factory or something similar.

This constraint makes it a pain to write fast tests, unless I’m missing something…

  • 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-19T15:16:38+00:00Added an answer on May 19, 2026 at 3:16 pm

    True, the error message is a bit obscure. Regarding your second point, you don’t need to save an object to generate a URL, the helper will work just as well with a literal value.

    building_path(1) # GET /buildings/1 => BuildingsController#show, params={:id=>"1"}
    

    So in the example the object can be replaced with any value:

    get :show, :id => "1"
    

    For example, if you use rails generate scaffold Article, RSpec will build a spec like this:

      def mock_article(stubs={})
        (@mock_article ||= mock_model(Article).as_null_object).tap do |article|
          article.stub(stubs) unless stubs.empty?
        end
      end
    
      describe "GET show" do
        it "assigns the requested article as @article" do
          Article.stub(:find).with("37") { mock_article }
          get :show, :id => "37"
          assigns(:article).should be(mock_article)
        end
      end
    

    which does not hit the database.

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

Sidebar

Related Questions

Having read this link on RBAR and this , my understanding of RBAR amounts
Having read this question Immutable or not immutable? and reading answers to my previous
After googling and landing on SO and having read this other question Is it
Having read around it appears this should be possible. I have the following content
I am fairly certain this is a ten penny closure question. But having read
I have a .txt file having some text. I want to read this file
Scenario Having already read a post on this on the same site, which didn't
I'm having problems reading this one JPEG file using ImageIO.read(File file) - it throws
help me please i'm having the following issue: I'm trying to read a XML
Having read this article F# Versus Mathematics: Part One - Getting Started with BLAS

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.