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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:54:30+00:00 2026-06-07T11:54:30+00:00

I am relatively new to rails and think that my problem may, in part,

  • 0

I am relatively new to rails and think that my problem may, in part, be due to me lacking a clear understanding of the nature and Scope of Ruby’s Classes and the objects that they produce.

I am getting the following error:

Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id

Rails.root: /Users/rmcnairn/rails/search
Application Trace | Framework Trace | Full Trace

app/models/photo.rb:17:in `scanner'
app/controllers/suppliers_controller.rb:66:in `block in update'
app/controllers/suppliers_controller.rb:65:in `update'

After Creation of a Photo record. I would like to use that new record to reference an associated record (a Fabric), and call an instance method (Scan) on that record.
Scan is defined in the Fabric Class.

My records are setup so that
a Photo *has_many* Fabrics :through Fabric_Photos

This is a snapshot of my Photo Class and my attempt to find this association and call the scan method on it.

class Photo < ActiveRecord::Base

  has_many :fabrics, :through => :fabric_photos
  has_many :fabric_photos
  after_create :scanner
  accepts_nested_attributes_for :fabrics
  mount_uploader :image, ImageUploader


  def scanner
    if self.fabric == true    #fabric is a boolean column in the Photo table
      self.fabrics.first.scan
   else
    return
   end
  end
end

EDIT
I Have added the Relevant Supplier Controller code
Suppliers have_many fabrics, fabrics have many photos

   def update
     @supplier = Supplier.find(params[:id])

     respond_to do |format| # line 65
       if @supplier.update_attributes(params[:supplier])
         format.html { redirect_to suppliers_url, notice: @supplier.name.to_s + ' was updated' }
         format.json { head :no_content }
       else
         format.html { render action: "edit", notice: @supplier.name.to_s + ' was NOT updated'  }
         format.json { render json: @supplier.errors, status: :unprocessable_entity }
       end
     end
   end

Would it be possible for you to help me understand a little more about the nature of the associated object that I am calling and the limitations, if any that are placed on calling methods on it in another class.

I presume that

self.fabrics.first

Is returning something that is incapable of having the method .scan called on it. It would be great is someone would explain to me what Active Record is actually producing here.

Many thanks

  • 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-07T11:54:32+00:00Added an answer on June 7, 2026 at 11:54 am

    Called id for nil, which would mistakenly be 4 — if you really wanted the id of nil, use object_id

    The issue is that self.fabrics.first is returning nil. In the underlying database, this means the sql query generated by Rails returned null.

    I would look at the controller code, or whatever you used to create the models. You may not be saving/updating the related models to connect everything. Also, take a look at each table and the id’s of the records there to see for yourself what is and isn’t being created.

    In the database, you should see that if you run the sql code rails generates (look in the log), that in the fabrics table you don’t have something that meets the query criteria.

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

Sidebar

Related Questions

I'm relatively new to Ruby on Rails. I need to use an iCalendar event
I'm having trouble with a regex in Ruby (on Rails). I'm relatively new to
I'm relatively new to Ruby on Rails 3 and hope to integrate Ambethia's Recaptcha
I'm relatively new to Rails development and I'm having a minor associations problem. I'd
I am relatively new to ruby on rails, so this question might be easy.
I'm relatively new to Ruby on Rails and occasionally I find this convention-over-configuration stuff
I'm relatively new to Rails, and I'm building an application that deals with weather
I'm still relatively new to Rails and Ruby - and after upgrading to the
I'm relatively new to Ruby on Rails. I'm using a particular gem my_gem in
So I am relatively new to Ruby on Rails and am building a project

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.