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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:21:32+00:00 2026-06-15T18:21:32+00:00

I have a class in Ruby (on Rails) as follows: class Good include MongoMapper::Document

  • 0

I have a class in Ruby (on Rails) as follows:

class Good
  include MongoMapper::Document
  has_many :offers, :dependent => :destroy

  key :name,         String
  key :description,  String
  key :email,        String
  key :offers,       Array
  key :type,         String
end

I am parsing a JSON object from an external URL and retrieve only a partial set of the types in this class, ie, I can retrieve only name, description, and type. On my server, I already have a page and data that can be displayed. I would like to display the data from the external URL on the page as well. How can I do this without making too many changes to the code? One thing I thought of was to make the strings I retrieve a part of the class Good, but I have no idea of how I can do it.

In other words, the retrieved name, description and type will be cast into the type Good and then will use the existing page, created to display our goods to display both, our, and the retrieved goods. How can I do this? Is this the right way of going about it?

  • 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-15T18:21:33+00:00Added an answer on June 15, 2026 at 6:21 pm

    Your question is pretty unclear, but I’ll take a shot. You could have a Struct like

    ArbitraryGood = Struct.new(:name, :description, :type)
    

    You could then map a collection of Good instances to this

    @arbitrary_goods = Good.all.map { |g| ArbitraryGood.new(g.name, g.description, g.type) }
    

    Then you can gather your JSON response and append new ArbitraryGood instances to it.

    objects_from_json = ... # for you to implement
    @arbitrary_goods += objects_from_json.map { |o| ArbitraryGood.new(o.name, o.description, o.type) }
    

    Now @arbitrary_goods contains a single listing mixed with data from both Good instances and the parsed external JSON for use within your view.

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

Sidebar

Related Questions

I have a ruby (1.9.3) on rails (3.1) app where: app/models/list.rb class List <
I'm using ruby 1.9.2 and rails 3.2.2. I have a 'domain' model (domain.rb): class
I have a ruby file as follows: module Example class Myclass def t_st Hello
I have this class in a ruby on rails application class ChartData def self.user_logs_by_day(logs)
I have RSS-reader class for Ruby, and I'd want to use it in rails,
I have a User model in my rails app as follows class User <
I have the following code: #!/usr/bin/ruby class Person def self.speak p = self.new puts
If I have the following piece of Ruby code: class Blah def self.bleh @blih
I am making a card game in ruby. I have the Game class, which
I have a ruby method (deactivate!) that is on an activeRecord class. However, I

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.