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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:59:49+00:00 2026-06-14T06:59:49+00:00

I’m slowly transitioning from beginning rails to an intermediate level. In my quest I’m

  • 0

I’m slowly transitioning from beginning rails to an intermediate level. In my quest I’m running into problems in the amount of time it’s taking for certain queries to load.

I’m wondering if someone could point out a few things that might improve the performance of my Index Action Query.

Running Rails 3.2.0, ruby 1.9.3p194, and MySQL

Right now I’m listing all institutions (around 7000) and it’s taking 10 sec’s to load …

My Index Action

  def index
    @institution = Institution.includes(:state).all
  end

View

<tbody>
    <% @institution.each do |c| %>
    <tr>
        <td><%= c.company %></td>
        <td><%= c.state.name %></td>
        <td><%= number_to_human(c.assets) %></td>
        <td><%= c.hadademo %></td>
        <td><%= c.datebecameclient %></td>
        <td><%= c.clientorprospect %></td>
        <% if current_user.admin? %>
            <td><%= link_to 'Edit', edit_institution_path(c), :class => 'btn btn-mini btn-warning'  %></td>
        <% end %>
    </tr>
    <% end %>
</tbody>

Institution Model

class Institution < ActiveRecord::Base
  attr_accessible :company, :phone, :clientdate, :street, :city, :state_id, :zip, :source, :source2, :demodate1, :demodate2, :demodate3, :client, :prospect, :notcontacted, :solveid
  belongs_to :state
  has_many :users, :through => :company_reps
  has_many :company_reps


  def points
    points_for_client + points_for_demodate1
  end

  def hadademo
    if demodate3.present?
        demodate3.to_date
    elsif demodate2.present?    
        demodate2.to_date
    elsif demodate1.present?    
        demodate1.to_date
    else
        "No Demo"
    end 
  end

  def datebecameclient
    if clientdate.present?
        clientdate.to_date
    else
        "Not a Client"
    end 
  end

  def clientorprospect
      if client?
            "Client"
        elsif prospect? 
            "Prospect"
        else
            "No Contact"
        end 
  end

  def points_for_demodate1
    if demodate1.present? && demodate1 >= Date.new(2012, 2, 23) or demodate2.present? && demodate2 >= Date.new(2012, 2, 23) or demodate3.present? && demodate3 >= Date.new(2012, 2, 23)
      1
    else
      0
    end
  end

  def clientcount
    if client?
      1
    else
      0
    end
  end

  def points_for_client
    if client?
      10 / users.count
    else
      0
    end
  end


end

Using Jquery Datatables

jQuery ->
    $("#institutions").dataTable
      sDom: "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>"
      sPaginationType: "bootstrap"

Log File

Started GET "/institutions" for xxx.xxx.xxx.xxx at 2012-11-13 02:51:47 +0000
Processing by InstitutionsController#index as HTML
  Rendered layouts/_messages.html.erb (1.2ms)
  Rendered institutions/index.html.erb within layouts/application (37190.3ms)
  Rendered layouts/_messages.html.erb (0.1ms)
  Rendered layouts/_navbar.html.erb (17.0ms)
Completed 200 OK in 43334ms (Views: 37983.7ms | ActiveRecord: 340.7ms)
  Rendered institutions/index.html.erb within layouts/application (34329.1ms)
  Rendered layouts/_messages.html.erb (0.1ms)
  Rendered layouts/_navbar.html.erb (23.3ms)
Completed 200 OK in 38824ms (Views: 34374.8ms | ActiveRecord: 82.2ms)
  • 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-14T06:59:50+00:00Added an answer on June 14, 2026 at 6:59 am

    If you look at the log you can see that all of the time is being spent on rendering your view, not the actual query. You will definitely want to implement view or action caching to speed this up.

    The official docs will point you in the right direction.

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string

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.