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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:00:39+00:00 2026-06-18T18:00:39+00:00

I am currently pretty stumped on this one. I recently had to update my

  • 0

I am currently pretty stumped on this one. I recently had to update my rails application and now am seeing this error popup whenever I try to save an object that also tries to save a Visitor object. Here is the code that is failing:

if @sale.shift_id.nil?
            @sale.update_attribute(:shift_id,session[:shift_id])
            @title = "New Sale"
            @sale = Sale.new
            @products = Product.order("name")
            @shifts = Shift.order("starttime")

#this line below is line 51, which the output says is the failing line.
            Visitor.new(:gender => 'Other', :shift_id => session[:current_shift_id], :reason_id => Reason.find_by_name("Products")).save

            redirect_to(newsale_path, :notice => 'successfully added the sale')
        else

The error I get is:

undefined method `to_i' for #<Reason:0x56f5848>
Rails.root: 

Application Trace | Framework Trace | Full Trace
app/controllers/sales_controller.rb:51:in `new'
app/controllers/sales_controller.rb:51:in `create'

At first I thought it might be the Reason.find_by_name, so I replaced that with a valid integer value and it still failed. The only other bit of code that I can see that might fail is the routes.rb, which has an entry under:

match 'newsale', :to => 'sales#newsale'

Lastly, the output to the webrick is confusing because it actually shows the sql calls saving the @sale object, and then I get the following lines:

SELECT "reasons".* FROM "reasons" WHERE "reasons"."name" = 'Products' LIMIT 1
Completed 500 Internal Server Error in 104ms
  • 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-18T18:00:40+00:00Added an answer on June 18, 2026 at 6:00 pm

    :reason_id => Reason.find_by_name("Products") here Rails is trying to cast the found Reason instance to an integer value to set as the :reason_id attribute on Visitor by calling .to_i on it (which doesn’t exist).

    You need to tell Rails where the id is by changing

    Reason.find_by_name("Products")
    

    to

    Reason.find_by_name("Products").id
    

    You can alternatively define a to_i method on Reason and leave your action as-is.

    alias_method :to_i, :id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I am using this query, which does a pretty good job of finding
Okay I'm looking for some input, I'm pretty sure this is not currently supported
This is currently pretty repetitive. I'm looking for a more DRY way to deal
Currently I'm developing a flight ticket search engine(pretty similar to this-http://www.momondo.com/) which will gather
I am currently working on a pretty large Java 6 application where we are
I am pretty new to iPhone development and currently working on an application which
I've been completely stumped on this one: I have the following python code: def
I can currently use sgml-pretty-print to pretty print an xml file in emacs, but
I'm currently in University and they're pretty particular about following their standards. They've told
I'm pretty new to the Symfony Framework and currently searching for the Best-Practice way

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.