Ruby on Rails Runtime Console - ruby-on-rails

I am trying to find a way to get a rails console for a program during runtime with all instantiated variables. The normal rails console does not have access to any instantiated variables of its respective running application. For example, when a rails application crashes during runtime, a webpage will load with the error listed in red text, a snippet of the code where the error was raised, and a console at the bottom with access to variables instantiated during runtime.
See image below for console im talking about
The best thing I could find was a gem called pry, which seems to allow you to access a console during runtime by adding the line 'binding.pry' in your code at the point where you want access to the console. I would be fine with this, but seeing as how rails already gives you access to this when your app crashes, I would think there is a "vanilla" way to do this. Unfortunately I can't find anything online about this feature in rails. This seems like such a valuable tool for debugging I can't see why rails doesn't implement this. Is there a better way to debug during runtime? a better gem?

I will suggest you to use Better Errors
Better Errors replaces the standard Rails error page with a much better and more useful error page. It is also usable outside of Rails in any Rack app as Rack middleware.

Related

Debugging in single file

Sometimes, I want to debug and test my rails code in a single file, instead of running a full rails app.
Is there a way to add the rails methods to a single file for debugging?
For example, I wanted to test and play with the delegate_missing_to method, but can't without running inside my actual rails app.
For testing ActiveRecord, I can use require 'active_record', which works really well, but I don't have access to other methods.
Any solution?
Check out bug reporting test cases from rails.
https://guides.rubyonrails.org/contributing_to_ruby_on_rails.html#create-an-executable-test-case
These are basically rails app in a single file.

How can I find out what prevents a rails app from loading a page?

I have a rails which seemed to be working previously but now after some changes when I go to the root page it takes it infinitely to load it, it just doesn't load it. There're nothing useful in the console either. How can I find out what prevents it from loading the main page? Is it about profiling?
Check your Rails logs, eg. development.rb. You can put logger.info, or puts statements in your environment.rb, development.rb and application.rb files to see how far Rails is getting in the boot process. You can also create a dumb initializer named 00_start_init.rb with a logger.info or puts statement to see if you're getting as far as initialization. I've found that useful before.
To really understand where you application is hanging, you need to understand the Rails initialization process. Here is the documentation for Rails version 4.2. http://guides.rubyonrails.org/v4.2/initialization.html. Similar documentation exists for every version of Rails. You can take advantage of understanding the boot sequence by placing log statement at various point in the process.
I'm assuming you're in the development environment. If so, and the console loads, it's likely not a configuration problem. It's more likely a problem with your controllers or models. If the console won't load to a prompt, then it's likely a configuration problem in application.rb, development.rb, an initializer, etc.
You mention profiling, but provide no details about it. I can't even guess what you're referring to, so the answer is "maybe?". If you can post the code changes you made since the app last loaded in the browser, that would make it much easier to help you trouble-shoot.

How do I debug errors with ActiveAdmin with Ruby on Rails?

There is a rails application that uses bunch of gems one of which is ActiveAdmin.
Dashboard works OK, but other custom tabs gets a 500 response.
How do I enabled debugging/logging inside ActiveAdmin gem to get to the bottom of this problem?
Corresponding generic question is this: what are the ways to enable debugging on rails apps with multiple gem dependencies?
1) Check your development.log file after hitting the custom tab page and see where the error was. The log should give you a stack trace or at least tell you the last controller that was hit. You can use this information to work backwards and find out where you code is breaking.
2) Once you have found the broken spot in the code you can use raise or pry debugger to inspect variables/methods to help you debug.
This turned out to be a version mismatch between the mongoid interface and the active admin interface.Thanks for all the help.

how to debug web server on RoR?

I currently have a problem with a project.
it freezes before it shows the "Started GET ...." seems like it hits an infinite loop.
now i dont really have much experience with debuggers in ROR, can anyone recommend anything i can use to trace the exact origin of the problem. if i can get an error code somewhere then i might be able to fix it.
currently i am using webrick, i tried thin and it gave the exact same error.but i am willing to use anything to find the exact origin of this error.
it seems to be related to the project because all other projects works fine on my environment.
Take a look at the Rails guide on debugging.
Also try running the Rails console ("rails c"); if you can get to a command prompt at all that means that the issue is not in loading the Rails environment (e.g. a problem in application.rb) but is somewhere in the process of making a web request. If there's a failure it may give you a better error message.

ruby on rails unable to find interface that appears to be proplery defined

I'm brand new to ruby on rails and trying to run an application developed by others. I downloaded it from SVN it running yesterday, but today when I try to run it the first attempt to access the site's home page I get the message:
expected .../app/helpers/interface/table_helper.rb to define Interface::tableHelper.
.../lib/active_support/dependencies.rb:452:in 'load_missing_constant'
This file exists, and properly defines the tableHelper interface. Since I was able to run the program when I was setting it up yesterday, and others can run it without issue, I assume the problem I'm seeing is caused by an incorrectly set up environment rather then bad code somehow.
Can anyone suggest what I might try to figure out why rails can't seem to detect a properly defined interface?
If you were able to run the program once, perhaps something got screwed up? Have you made any changes to the code?
Alternatively, try stopping and restarting the server.
Also: what's the application? Maybe we can look at the codebase...

Resources