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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:56:49+00:00 2026-06-13T08:56:49+00:00

The relevant piece of code in the controller is the following: logger.info(Dumping params) logger.info(params)

  • 0

The relevant piece of code in the controller is the following:

    logger.info("Dumping params")
    logger.info(params)
    logger.info("Dumping initial cost:")
    logger.info(@cost)
    logger.info("entering if statement")
    if params.has_key?("special_edition") && params["special_edition"] == 'yes'
      @cost = @cost + 50000
    end
    logger.info("If we get to here then the first conditional executed correctly")
    if params.has_key?("number_of_lids") && params["number_of_lids"].to_i > 0
      @cost = @cost + (params["number_of_lids"].to_i * 5000)
    end
    logger.info("If we get to here then the second conditional executed correctly")
    logger.info("printing final cost:")
    logger.info(@cost)

When I run the app, I get a 500 error. Checking into the log file (test log file), I see the following:

Dumping params
{"utf8"=>"✓", "special_edition"=>"yes", "number_of_lids"=>"3", "action"=>"create"}
Dumping initial cost:
350000
entering if statement
Completed 500 Internal Server Error in 1922ms

If I enter the console (rails console), and run this code (values taken from the log file:

params = {"utf8"=>"✓", "special_edition"=>"yes", "number_of_lids"=>"3", "action"=>"create"}
@cost = 350000
if params.has_key?("special_edition") && params["special_edition"] == 'yes'
    @cost = @cost + 50000
end
if params.has_key?("number_of_lids") && params["number_of_lids"].to_i > 0
    @cost = @cost + (params["number_of_lids"].to_i * 5000)
end

Then I get the correct result for @cost: 415000

Any ideas why I might be getting a 500 error?

Clarification:

Several responses mentioned that the difference is that the difference is that I’m initializing @cost but not doing it in the controller. The code that’s initializing @cost is not included, because it is already initializing properly. I included the piece of code that logs @cost to the log file and I am initializing it in the console using the value I am getting for @cost from the log file (see my code, lines 3 & 4 and then the output from the log file lines 3 & 4)

I tried to use the comment feature, but stackoverlfow is giving me an error message.

Resolution

It turns out that another module in the app was reading the interget @cost and turning it into a string. This was masked by another bug in the app, so an earlier test failed. Moral of the story: regression testing is essential. Using @cost.to_i fixed the problem

  • 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-13T08:56:49+00:00Added an answer on June 13, 2026 at 8:56 am

    Just try

    if params.has_key?(:special_edition) && params[:special_edition] == "yes"
    

    if the error persists, just check if the @cost is an integer by assigning a value or with the to_i method.

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

Sidebar

Related Questions

I have the following piece of code (only relevant parts): xhttp=new XMLHttpRequest(); xhttp.open(GET,doc_name,false); xhttp.send();
I don't know that the following piece of code is really relevant, but for
I am looking for something in the following piece of code so that the
Relevant Code Snippet: public class MyPreference extends Preference { public MyPreference(Context context, AttributeSet attrs)
Here's the relevant code: <div data-bind=foreach: chats, visible: chats().length > 0> <input data-bind='value: $parent.newCommentText'
Here is the code relevant to my question: http://jsfiddle.net/mkerny45/V23NK/ As you can see there
Here's the relevant code snippet. public static Territory[] assignTerri (Territory[] board, String[] colors) {
Here's the relevant code: public static void printBoarders (Territory x) { int t =
I just created a big piece of code I want to commit in several
I've got this nifty little piece of code here that self-propogates ad infinitum every

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.