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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:25:04+00:00 2026-05-14T03:25:04+00:00

I was trying in Ruby on Rails how to find a prime number. Here

  • 0

I was trying in Ruby on Rails how to find a prime number. Here is my code :

helper : app/helpers/test_helper.rb

module TestHelper                
  def prime_number? number     
    index = 2                    
    tmp = 0                      
    while index <= number        
      if tmp < 1                 
        if (number % index) == 0 
          tmp += 1               
        end                      
      else                       
        return false             
      end                        
      index += 1                 
    end                          
   return true                   
  end                            
end

and my view : app/views/test/index.html.erb

<% (2..100).each do |i| -%>
  <% if prime_number? i %>
    <%= i %>
  <% end -%>
<% end -%>

So my question is : How can you load data while it’s calculating ? I mean if I replace 100 by 100000 in my view, how can I see data on my view while my helper method is calculating ?
Do I need to use ajax or rails provide a tool for that ?

Thank you.

  • 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-14T03:25:04+00:00Added an answer on May 14, 2026 at 3:25 am

    Short answer: yes, you’ll need AJAX.

    Longer answer: you can use the Prototype Helper periodically_call_remote to poll one of your actions and add new prime numbers to the end of the list.

    There is an issue though, Ruby is very slow compared to native OS languages such as C. If you want to get the most prime number results, I’d write the prime number code in C and find a mechanism to access the results. One way to do that would be to have your C application write prime numbers to a file and you can tail -f that file to get the new primes. I’m sure you can find a C example for finding prime numbers somewhere.

    Even if you were to write the prime number code in Ruby, you’d have to run it as a separate process from your Rails application for it to continually calculate primes, so you might as well do it in something faster. Actually, Ruby might not be too terribly slow for this calculation, it’d be interesting to benchmark the two.

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

Sidebar

Related Questions

I'm trying to write an app using Ruby on Rails and I'm trying to
In Ruby, I'm trying to do the following. def self.stats(since) return Events.find(:all, :select =>
Why do I get following error when trying to start a ruby on rails
I'm trying to write an import rakefile for Redmine. It uses ruby on rails.
I'm just learning ruby and trying to understand the scope of code executed in
I'm trying to do Ruby password input with the Highline gem and since I
I am trying to learn Ruby, and want to implement the Python algorithms from
Using Ruby I'm trying to split the following text with a Regex ~foo\~\=bar =cheese~monkey
In Ruby, trying to print out the individual elements of a String is giving
I've been trying to understand how Ruby blocks work, and to do that I've

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.