A copy of [middleware] has been removed from the module tree but is still active! - error - ruby-on-rails

We use rails version 2.3.5
This error has been reported in SO here
I tried the following:
adding config.cache_class = true - the problem with this was that, the server had to be restarted every time a change was made to any controller. Also the server start time was too long
adding unloadable to the middleware - no use
adding config.middleware.use [middleware] to development.rb - no use
Is there a way to overcome this other than making development similar to production?
Edit
even tried adding config.middleware.use [middleware] to environment.rb. Well this behaved totally different. My error disappeared, but my middleware cracked. All it's objects were nil..!

maybe you need to make a plugin reloadable?
refs: http://blog.yves-vogl.me/2010/01/12/automatically-reload-rails-plugins/
Rails auto-reloading plug in development mode
et al

Found the answer.
adding config.middleware.use [middleware] to environment.rb
this was not working previously for me because i was initializing this middle ware inside session_store too. So the same middle ware was executed twice with the second time all params with nil - Hence the nil problem.
Thank you rogerdpack for trying to help.!

Related

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.

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

how does a middleware get deleted?

rack-timeout is included in the Gemfile, but we only want it as middleware on production. Thus in an initializer, we have:
config.middleware.delete Rack::Timeout
Inspecting before and after this line shows rack-timeout removed from the array. Regardless, requests are still timing out, and a quick 'puts' in the gem shows that it is indeed the culprit.
Is this because the middleware stack has already been built before delete is called? Or is the stack read in every request? If that's the case, what could be the issue?
Why not just have something like the following?
group :production do
gem "rack-timeout"
end
In theory, the middleware deletion in the initializer should take care of the problem after a server restart, assuming you're talking about putting something in config/initializers/.
Did a little more experimentation and dropped this into config/initializers/rack-timeout.rb:
if Rails.env.production?
Rack::Timeout.timeout = 0.5
else
Rails.configuration.middleware.delete Rack::Timeout
end
And this in a scaffolded controller:
sleep 1
Everything seemed cool after I restarted the dev server (no timeouts in sight :D). So, maybe just a bad variable.
I still think using a production-only group is the better solution.
Ran with Rails 3.2.2 with ruby 1.9.2-p290 on OSX.

Rails 3 development environment keeps caching, even without caching on?

i have a rails 3 app in dev mode that won't load any changes i make when its running webrick. i triple checked the settings for my development.rb and made sure i am running in development mode.
config.cache_classes = false
config.action_controller.perform_caching = false
i also checked my tmp directory to make sure the cache folder is empty - i have yet to do any caching on the site and have never turned on caching. im guessing its a loading problem with the files.
also i was running on webrick then installed mongrel and the problem still persists.
im guessing ive run into a config problem, bc i dont see anyone else posting such a prob. anything else im missing?
EDIT: it looks like my view helpers aren't auto loadable - aren't helpers by default supposed to be reloadable in rails 3?
I've had a similar experience, but I don't believe it was with an actual helper class, it was with anything I wrote under the lib/ directory. If you've had to use a require 'some_class' statement, then you should switch it to:
require_dependency 'some_class'
Worked like a charm for me.
I had the same problem and here is the simple solution.
In your config/environments/development.rb set following settings:
config.action_controller.perform_caching = false
config.perform_caching = false
config.cache_store = :null_store
I know this is an old question, but for anyone coming here with a similar issue, make sure you didn't accidentally move production.rb from config/environments/ to config/initializers/ like I did. That will make Rails read in the production.rb file and override your development settings. Whoops.
Had the same issue, it was caused by rails-dev-tweaks gem which is, if you used default configuration from README, disabling stack reload upon AJAX requests.
I'm using Rails 4, and my cache call was in a helper using Rails.cache.fetch.
After googling a bit, I found out this issue (https://github.com/rails/rails/issues/20733), where a PR was merged into rails 5 documentation to make clear that '
Changing the value of config.action_controller.perform_caching will
only have an effect on the caching provided by the Action Controller
component. For instance, it will not impact low-level caching, that we
address below.
', being 'low-level-caching' the Rails.cache.fetch.
It's on the docs now: http://guides.rubyonrails.org/caching_with_rails.html

Rails Application expecting me to restart my webrick server for any change in my controller

I am working on an existing Rails 2.3.x application, So I was working on it and it was a messy code with great difficulty I was able to run the application. But now for every small change in one of my controller it is expecting me to restart my serer otherwise the changes are not reflecting back, Let's take an example scenario here, Let's just say in one of the before_filter method I just added a puts statement on top of the method and it was not printing in the log, after I restart the server it is printing, Can some one please let me know if I am missing something here.
What environment are you using?
The default environment is 'development', where the code is reloaded on each request. However, this behaviour can be overwritten in the config file.
To be sure that the code is reloaded, add this into your config/development.rb file:
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
If you are using config.threadsafe! It needs to be present before config.cache_classes=false as threadsafe makes cache_classes true again, following link would make it more clear. here
Maybe you have don't flush. The log system in Rails use a BufferedLogger. So need a flush to be print. Try a default logger.

Resources