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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:12:40+00:00 2026-06-01T20:12:40+00:00

We are porting MiniProfiler to Ruby and wanted to add auto instrumentation for Rails

  • 0

We are porting MiniProfiler to Ruby and wanted to add auto instrumentation for Rails views and partials.

I am aware of the existing instrumentation support but ideally want to get “start” and “stop” events. We would also like to support earlier versions of Rails that do not have notification support.

I hacked up a short instrumenter and tested hooking up render with before and after calls:

def prof(klass, method)
  with_profiling = (method.to_s + "_with_profiling").intern
  without_profiling = (method.to_s + "_without_profiling").intern

  klass.send :alias_method, without_profiling, method
  klass.send :define_method, with_profiling do |*args, &orig|
    puts "before #{method} #{args}"
    self.send without_profiling, *args, &orig
    puts "after #{method}"
  end
  klass.send :alias_method, method, with_profiling
end

prof ActionView::Template, :render

However, once this is activated render is not instrumented properly. In particular this works on some of the partials, but explodes with a:

ActionView::Template::Error (undefined method `html_safe’ for nil:NilClass)

What is wrong with this method hook? What is a proper robust way to hook methods so they are not fragile to this problem (maintaining the trivial API: prof klass, method)

  • 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-01T20:12:41+00:00Added an answer on June 1, 2026 at 8:12 pm

    You’ve redefined the method to return the result of your final puts which is usually nil. A fix might be:

    klass.send :define_method, with_profiling do |*args, &orig|
      puts "before #{method} #{args}"
      result = self.send without_profiling, *args, &rig
      puts "after #{method}"
    
      result
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on porting an existing VB.Net application to Java, and could not
I am porting some existing C code to run on Android. This C code
I'm porting some C++ to Java, and encountered the following shorthand..but have no idea
Im porting some calculation routines from .Net to Java but there seem to be
Back-porting an app to Android 1.5, I fix VerifyError bugs all the time, but
Porting an application from C# (1.1 framework) to VB.NET (3.5 framework), and I have
Porting code from 32bit to 64bit. Lots of places with int len = strlen(pstr);
I am porting a Delphi application to C# and I've run into a problem.
For a Perl porting project I am using ActiveState's Komodo IDE 5.1 For external
I am working on porting over a database from a custom MSSQL CMS to

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.