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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:46:01+00:00 2026-05-26T15:46:01+00:00

I am having some problems creating a loop that could show the cheapest price.

  • 0

I am having some problems creating a loop that could show the cheapest price.

Here is my controller:

   def domain
    country_codes = ['.dk', '.com', '.eu', '.net', '.org', '.biz', '.info', '.nu', '.name', '.se', '.fi', '.net', '.de', '.it'] # etc. could move this to a config if needed
    @domain = params[:domain]
    @results = {}
    country_codes.each do |cc|
    @results[cc] = Whois.whois(@domain + cc)
    end
    @pricedk = Domain.sort("dk ASC").first
    @pricecom = Domain.sort("com ASC").first
    @priceorg = Domain.sort("org ASC").first
    @pricenet = Domain.sort("net ASC").first
    #ETC... 
end

My view:

<table border="0" bordercolor="#FFCC00" width="700" cellpadding="0" cellspacing="0">
    <tr class="top">
        <td class="checkdomain"></td>
        <td>Name</td>
        <td>Domain</td>
        <td style="font-size:9px;"></td>
    </tr>
     <% @results.each_pair do |country_code, available| %>
    <% klass = available.registered? ? "pinfo" : "info" %>
    <tr>
        <td><span class="<%= klass %>"></span></td>
        <td><%= @domain + country_code %></td>
        <td>PRICE HERE</td>

    </tr>
     <% end %>
</table>

I want to DRY the @pricecom, @pricedk, @priceorg up.
How do I include it in the @results loop?

  • 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-26T15:46:02+00:00Added an answer on May 26, 2026 at 3:46 pm

    When you have repetition like this, with many different instance variables, what you need to do is roll them all up into a single instance variable that’s a Hash:

    def domain
      country_codes = %w[ dk com eu net org biz info nu name se fi net de it ]
    
      @domain = params[:domain]
    
      @results = { }
      @prices = { }
    
      country_codes.each do |cc|
        @results[cc] = Whois.whois("#{@domain}.#{cc}")
        @prices[cc.to_sym] = Domain.sort(cc).first
      end
    end
    

    You’ll see this pattern every so often. @pricesdk becomes @prices[:dk]

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

Sidebar

Related Questions

I am having some problems creating a query that gives me the average of
I seem to be having some problems creating a jquery plugin. I am testing
I'm having some problems creating a view for a node within my website. The
I'm creating a messaging web app in ASP.NET and are having some problems when
I'm having some problems with creating pagination with a HABTM relationship. First, the tables
I'm creating some UIButton s programmatically in a loop but I'm having some problem
Im having some problems creating a custom search form for jqGrid, on the last
I'm having some problems creating a process to hide a region in pl/sql. Can
I am having some problems creating custom types for my data table, using jquery.datatables.js.
Having some problems with creating regular expression with subpatterns on php. Need some help.

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.