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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:39:43+00:00 2026-06-11T12:39:43+00:00

I am getting the error undefined method `div’ for 11:String pointing to the @startdate

  • 0

I am getting the error

undefined method `div’ for “11”:String”

pointing to the @startdate line when I submit the form. I don’t understand what’s going on at all. If I do the steps in the rails console it works fine.

In my controller I have:

@startday = params["startday_#{i}".to_sym]
@startmonth = params["startmonth_#{i}".to_sym]
@startyear = params["startyear_#{i}".to_sym].to_s
@endday = params["endday_#{i}".to_sym]
@endmonth = params["endmonth_#{i}".to_sym]
@endyear = params["endyear_#{i}".to_sym].to_s
@startdate = params["startdate_#{i}".to_sym]
@price = params["price_#{i}".to_sym]
@currency = params[:currency]
@startdate = Date.new(@startyear, @startmonth, @startday)
@enddate = Date.new(@endyear, @endmonth, @endday)

The hash I am sending is:

{
  "startmonth_1"=>"2",
  "startday_1"=>"11",
  "startyear_1"=>"12",
  "endmonth_1"=>"2",
  "endday_1"=>"13",
  "endyear_1"=>"12",
  "price_1"=>"12",
}

If I do a

@startee = @startyear.to_s + '-' + @startmonth.to_s + '-' + @startday
return render :text => @startee

I get:

12-2-11

So I don’t see the problem. Everything seems to be working ok.

  • 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-11T12:39:44+00:00Added an answer on June 11, 2026 at 12:39 pm

    You’re passing strings to Date.new when you need to pass integers:

    @startday = params[:"startday_#{i}"]
    @startmonth = params[:"startmonth_#{i}"]
    @startyear = params[:"startyear_#{i}"].to_s
    @endday = params[:"endday_#{i}"]
    @endmonth = params[:"endmonth_#{i}"]
    @endyear = params[:"endyear_#{i}"].to_s
    @startdate = params[:"startdate_#{i}"]
    @price = params[:"price_#{i}"]
    @currency = params[:currency]
    
    @startdate = Date.new(@startyear.to_i, @startmonth.to_i, @startday.to_i)
    @enddate = Date.new(@endyear.to_i, @endmonth.to_i, @endday.to_i)
    

    Further, if you don’t need to use these variables in your view, there’s no need to make them instance variables and you should make them local variables instead (i.e. drop the leading @ in the name).

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

Sidebar

Related Questions

undefined method 'key?' for nil:NilClass This is the error I am getting while going
I'm getting the following error: undefined method `id' for #<Array:0x00000101ff0b70> On this line: <%=
I'm getting this error : undefined method `has_many' for #<Formtastic::SemanticFormBuilder:0xb410d4c> It work when I
I am getting the following error Fatal error: Call to undefined method MongoCollection::command() in
I'm creating some basic OO scripts using MySQLi and getting an Undefined Method error
I'm getting a no method error in my Static_pages#home: undefined method `exists?' for Registry
Doing the getting started of Sinatra. I get this error: ./sinatra.rb:5: undefined method `get'
I have a problem where a method is getting an undefined variable error, even
I'm getting this error : undefined local variable or method sessions_path' for #<#:0x2db44c8> when
I'm getting the error: undefined method `model_name' for NilClass:Class when trying to call the

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.