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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:20:09+00:00 2026-05-26T12:20:09+00:00

This code from my developer below… does it expect something like 1 – January

  • 0

This code from my developer below… does it expect something like “1 – January” and try to parse it into something else?

I changed the code on my form so now the value being passed to this controller is just “1” instead of “1 – January”

How can I fix this so I don’t get the “can’t convert nil into string” error?

  def get_expiry_month_number(monty_det, expiry_year)
    if MONTH_NAMES.include? monty_det
       month_number = MONTH_NAMES.index(monty_det)
       month_number = MONTH_NUMBERS[month_number]
       expiry_year = month_number.to_s + expiry_year[expiry_year.length-3..expiry_year.length-1]
       return expiry_year
    end
  end
  • 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-26T12:20:09+00:00Added an answer on May 26, 2026 at 12:20 pm

    In your example you are running into the problem that one of your strings in your calculation for year is nil. Most likely this one,

    expiry_year[expiry_year.length-3..expiry_year.length-1]

    You can try and fix this by calling to_s on the culprit variable, thus converting the nil into '' and then concatenated.

    Like so: expiry_year = month_number.to_s + expiry_year[expiry_year.length-3..expiry_year.length-1].to_s

    However, this may have other seen consequences and isn’t recommended. A better approach would be to find out why something you expect is a string is turning out to be empty, and perhaps displaying an appropriate error.

    Could you explain a little bit more about what the function is supposed to do? And perhaps the value of expiry_year and monty_det when the error occurs? puts statements can be a big help here.

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

Sidebar

Related Questions

I'm refactoring some code I inherited from a long-gone developer, and I find this:
I got this code from the wordpress <head profile=http://gmpg.org/xfn/11> What does this means? what
Got this code for a viewscroller from the apple developers site. @synthesize scrollView1, scrollView2;
i develop this code: SELECT COUNT(NewEmployee.EmployeeID), NewEmployee.EmployeeId,EmployeeName FROM NewEmployee INNER JOIN NewTimeAttendance ON NewEmployee.EmployeeID
In this code (from the WCF REST starterkit - preview2): protected override SampleItem OnAddItem(SampleItem
I'm using this code from Microsoft to play audio notifications for my application. It's
I copied this code from an example . I've read it 100 times. Array.prototype.map
I found this code from here: http://www.cssportal.com/form-elements/text-box.htm But the problem is you can still
I got this code from someone, it's almost perfect to create a dynamic breadcrumb,
I got this code from someone and it works very well, I just want

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.