Why does the Rails Debugger not default to Autoreloading? - ruby-on-rails

This drove me nuts for the longest time and I thought my rails s was not reloading my code when in fact the debugger was not reloading it.
Then I found from this post that auto-reloading is not default. WHY NOT???
If you are debugging code, and you see an error, you are clearly trying to change it. And when you change it and the debugger keeps your old buggy code, what's the point?
I would like to set autoreloading to default but right now you have to do this:
rdebug reads its configuration file at startup.
create a file ~/.rdebugrc with this content:
set autoreload
or an explanation of how I am using the debugger incorrectly. Thank you very much!

This Pivotal Labs article should give the answer.
Caveat: This worked on my Ubuntu environment, but in my current setup (Mac OS X) I can't get changes in controllers auto reloaded even with this. Could you let me know your setup and if it works for you?

Related

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.

Rails not auto loading engine code

I have some rails apps and rails engines, their structure is like this:
rails_app_1/
rails_app_2/
etc......
rails_engine_x/
rails_engine_y/
rails_engine_z/
rails_engine_w/
Each rails_app loads a subset of these engines, so for example rails_app1_1 Gemfile may have this code
gem 'rails_engine_x','0.0.1', path: '../rails_engine_x'
gem 'rails_engine_y','0.0.1', path: '../rails_engine_y'
Now the problem is that on development mode, when changing some code, it seems that code auto loading is broken and I get strange errors that are fixed when I close the server and open it again. For example I may get some errors like (Constant Foo is not defined-where it is actually defined-), and other times I got some error(undefined method serialize_from_session for #<Class:0x00000009762628>) which is a method from devise defined on User class which was working normally, only when changing the code in development mode while the server is running then it is not defined. So I need to restart the server to get the code reloaded correctly. Any help on this? I read about rails auto loading but couldn't find a clue.
Ok the problem is solved, it was because of a strange initializing code that was trying to include some modules manually, when I changed it, every thing worked.

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.

Rails: How to make require reload on every refresh?

I've notice that when I include password hashing with require "digest/sha1" on top of my model, every time I make some change in my app, I have to restart server to see changes.
That is kind of annoying and it is slowing down development a lot, especially for beginner like me.
I've seen somewhere that with require_dependency "digest/sha1" it should work, but it is not working for me (saying no file error).
I'm not sure even where to put require_dependency as I haven't found any example.
There should be some way to make it work, as it is quite common problem, maybe I was just looking to wrong places.
Thanks
EDIT :
I've came to conclusion that error comes when my Ubuntu machine goes to sleep. After wake up, local server (tried thin and WEBrick) give that error.
EDIT :
It has nothing to do with Ubuntu sleep. I had a function named hash that was giving errors every time, complaining that it got wrong number of arguments, but that function was never called.
So, I've renamed it to encrypt and now it is working, but I'm not 100% sure that it is solution, I have to test is more.
If it will be ok, that would be a strange bug, I will post an answer.
In development mode, by default, anything in app/ or config/routes.rb is reloaded between requests. If this is not happening for you, it's probably not caused by the require. It's more likely that you've turned off reloading inadvertently.
I've used digest/sha1 in many projects before and have never had this problem, usually including it in the User model where it's used.
Can you replicate this problem in a brand new Rails project? Does the problem go away if you remove that line? If so that is very odd.
If you remove require "digest/sha1" all works fine?
Anyway check for config.cache_classes = false in config/environments/development.rb

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