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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:08:15+00:00 2026-06-07T12:08:15+00:00

I have this error in two of my tests: test should create question do

  • 0

I have this error in two of my tests:

test "should create question" do
  assert_difference('Question.count') do
    post :create, question: { question: 'apple', answer: "good", holder_id: 2}
  end
end

test "should not create question" do
  invalid_answer = "a" * 145 
  assert_difference('Question.count',0) do
    post :create, question: { answer: invalid_answer }
  end
  assert_template 'new'
end

My create action

#create action
def create
  @question = Question.new(params[:question])
  @holder = Holder.find_by_id(@question.holder.id)
  if @question.save
    flash[:success] = "Question Saved"
      redirect_to holder_path(@question.holder_id)
    else
        render 'new'
    end
end

The stack trace shows it is on the create line both times. But, how come I get the Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id error?

Do I need to create an object first and then pass that in to the post create?

  • 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-07T12:08:17+00:00Added an answer on June 7, 2026 at 12:08 pm
      @question = Question.new(params[:question])
      @holder   = Holder.find_by_id(@question.holder.id)
    

    Yes you were right, you need to create the Holder instance before running this test.

    But why do you create all the ivars, do you need them in new?

    If not it seems the code can be dryed up to

    def create
      question = Question.new(params[:question])
      if question.save
        flash[:success] = "Question Saved"
          redirect_to holder_path(question.holder) # but some checks are in order here, no?
        else
            render 'new'
        end
    end
    

    HTH
    Robert

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

Sidebar

Related Questions

I have been struggling with this error for more than two hours: error: aggregate
So I have this form: <form name=login id=login action= method=POST onSubmit=return test()> <input type=text
I have a problem with IE causing two errors: 1. Object doesn't support this
I have this error when trying to generate the meta model with JOOQ: org.jooq.exception.DataAccessException:
I Have this error message : Possible unitended reference comparison; to get a value
I have this error message: Msg 8134, Level 16, State 1, Line 1 Divide
I have this error that is keeping me from moving forward. I basically have
I have this error message could not load assembly 'system.data.entity, version 4.2.0.0, culture=neutral,publickeytoken=b77a5c561934e089' or
I have this error when I am trying to read the file: Exception in
I have this error appearing in my web service and even though I'v had

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.