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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:24:07+00:00 2026-05-31T03:24:07+00:00

Hi I have a model called Listing. Here is the constructor for the model:

  • 0

Hi I have a model called “Listing”.
Here is the constructor for the model:

def initialize(business)
    puts 'inside Listing.initialize'

    @name = business.name
    @telephone = business.telephone


    puts 'Created a new Listing'
end

I have a controller called “listings_controller”
I have is another model called “Business”. Inside the “listing_controller” I have a method in which I would like to instantiate a “Listing” with attributes of a “Business”.

Here is the code that does that in a “listings_controller”

def create_listings

    self.get_all  
    @businesses.each do |business|
     Listing.create(business)

    end

end


def show

   self.create_listings
   @listings = Listing.all

   respond_to do |format|
   format.html #show.html.erb
   end

end

This initialization method is not working.Im getting this exception:

wrong number of arguments (2 for 1)

Rails.root: /Users/AM/Documents/RailsWS/cmdLineWS/Businesses

Application Trace | Framework Trace | Full Trace
app/models/listing.rb:53:in initialize'
app/controllers/listings_controller.rb:18:in
block in create_listings’
app/controllers/listings_controller.rb:17:in each'
app/controllers/listings_controller.rb:17:in
create_listings’
app/controllers/listings_controller.rb:26:in `show’

How can I fix this?
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-05-31T03:24:08+00:00Added an answer on May 31, 2026 at 3:24 am

    You could try (pseudocode/untested):

    def initialize(business)
        puts 'inside Listing.initialize'
    
        @attributes.merge(business.attributes)
    
        puts 'Created a new Listing'
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model called Details, and two controller methods new and create. New
I have a model name called StoreEntry. Django admin changes it to look like
I have a model called folder that acts as a tree. Inside the model
I have a model called Product with a custom property: def _get_active(self): o =
I have a Model called blog_model. The code for its constructor is below: class
I have model/controller called notification. I want to make a new url so that
I have a model called Contact which has_one guest like so. class Contact <
I have a model called Answer which has a ForeignKey relationship to another model
I have a model called company that has_many users then users belongs_to company. class
Say I have a model called User that has the following parameters: favorite_color, favorite_animal,

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.