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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:38:49+00:00 2026-06-06T12:38:49+00:00

Basically, I want to generate an item, in this case, a ring. I have

  • 0

Basically, I want to generate an item, in this case, a ring. I have different TYPES of rings:

class Ring < ActiveRecord::Base

  DISPLAY_NAMES [ 'Silver', 'Gold', 'Diamond' ]

  attr_accessible :description, :display_name, :roll, :bonus, :total, :image, :gold

end

Is there a way to randomize the DISPLAY_NAMES of rings?

I’m guessing something like @ring.display_name = rand(Ring::DISPLAY_NAMES)?

Is there a better way to do this?

Once that is found, is there a way to set all other attributes of the ring, like @ring.roll and @ring.bonus, etc..

For example, if a ring comes up as silver, can I declare in the model some kind of if statement that states if the ring is silver and the other attributes are bla bla bla?

Thanks in advance. Learning slowly but surely.

  • 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-06T12:38:52+00:00Added an answer on June 6, 2026 at 12:38 pm

    To get a random entry from the DISPLAY_NAMES array do

    @ring.display_name = DISPLAY_NAMES.sample
    

    check http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-sample

    For the second part, if the rest of the values are static and will not change, then I would just seed them in seed.rb

    Populate the db with all the values for each [ 'Silver', 'Gold', 'Diamond' ]
    So, you will have 3 records in the db for each name.

    After that, you can do

    @ring = Ring.find_by_display_name(DISPLAY_NAMES.sample)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to generate time-stamp in this format yyyymmdd. Basically I want to create
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
I have a large multidimensional array and I basically want to drop the first
I have an SPListItemCollection. I basically want to get one of the items (randomly)
i'm experimenting with django and the builtin admin interface. I basically want to have
Basically I want to generate random numbers that won't ever repeat for a very
Or am I thinking about this wrong? Basically, I want to be able to
I have a list of products I want to generate xml for currently all
I basically want to write me a bash script, where I'd generate a couple
basically I want to encapsulate a simple component from code that I already have.

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.