How to debug Rails application? - ruby-on-rails

I'm new to Ruby on Rails and I'm facing quite a number of logical errors which I'm unaware of. Like a normal programmer, the thing to solve your errors is by debugging it first. May I know how to debug it? Because when i tried doing so, it already shows me an error:
"Uncaught exception: uninitialized constant Object::ApplicationController"
May I know how to solve this error and how to debug? Thanks! :)

You can either do it the quick and dirty way, in your code:
raise my_object.inspect
This will throw an exception with the information about the object.
Or use the ruby-debug gem.
I recommend you read the Debugging Rails Applications chapter in the Rails documentation.

Related

Ruby on Rails Runtime Console

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.

Rails already initialized constant HELP_MAPPINGS

I am working through the Ruby on Rails Tutorial Sample app and I don't understand how I can fix the warning and the multiple tests that get run every time but don't do anything.
Screenshot of multiple tests running with the warning.
I am unsure if this is messing with performance or if it something I should just ignore, but I would like to resolve this issue if possible.
Thanks for the help, friends!

Rails annoying message We're sorry, but something went wrong

****We're sorry, but something went wrong.
If you are the application owner check the logs for more information.****
On various rails applications I have been getting this all the time. How can this be fixed for good on ruby on rails apps?
You will have to check the log and fix the error, for production application you can use services like airbreak or errbit a free solution. Whenever this page occurs you will receive full trace and error. Hope this will help you in making application much more stable.

Rails Server and Console crashing because of unexpected break (LocalJumpError)

I'm getting this weird behaviour when running rails server or rails console.
The server/console crashes in various locations in the code throwing this exception:
script/rails:6:in `require': unexpected break (LocalJumpError)
from script/rails:6:in `<main>'
I must note that this behaviour happens to only one more person in my team, all other members of my team does not experience this behaviour and also production server is working just fine with no crashes like this.
Also, we found putting debugger somewhere in the code and just pressing continue solves this problem. But this is hardly a logic way to deal with this bug.
Does anyone experienced similar behaviour and knows how to solve this?
I have not enough information to provide a 100% sure solution, but here is my guess :
Try to use bundle exec rails <command> rather than script/rails <command>. Rails script doesn't have changed for some time, but it may just be you're not loading the correct gem dependencies.
It would be interesting to know if the other person of your team getting the problem is using script/rails too. If all other people having no problem use the rather idiomatic bundle exec rails, you have a good clue for a dependency version problem.

Ruby on Rails application could not be started

As you can see at https://ssl.virtualweb.at/redmine/ i try to get Redmine up & running.
At the start i got this error:
undefined method `mattr_accessor' for ActiveSupport::Deprecation:Module
Could someone be so nice an give some tipps how to get it to run?
t.i.a.
Can you give us a little more information? For example - can you go and look at the logs and find the full backtrace of the error that is occurring?
Otherwise we don't know where the error is occurring. Then we can narrow it down a bit better
My best guess atm, though, is that you have the wrong version of ruby or rails or rake (or something similarly important). mattr_acessor is a fundamental method in ruby - so I'd start by reading the redmine docs to see what version of ruby you need.
Then go check if you've got that version installed... repeat with rails, required gems etc.

Resources