I have this bizarre behavior that I cannot even debug. Usually development is supposed to run a little slower than production. Not only is it now running extremely fast, but it does not recognize my javascript code (it does recognize javascript outside of the assets/javascripts directory), unless I modify the javascript code and refresh page or simply just refresh the page (and then it will only work for that one request).
The reason why I am stumped is because I have the following in /config/environments/development.rb:
config.assets.debug = true
Furthermore, my development.rb is set to the factory defaults.
Any idea how I can further troubleshoot this issue?
Related
I am using an RoR opensource application, and I want to make some minor changes in it.
Like adding the possibility to use table in CKEDITOR, or embedded an other application to it.
I achieve doing all of this, but I can only see my changes, or style the embedded application if I set config.assets.debug = true in my environments file.
The problem is, when I do that, I have strange behavior in my application... Like when I submit a form, it is submitted twice...
And I absolutely don't know why...( I really don't know much in RoR )
Edit
It seems that the question is not clear... The fact is I don't know what to tell you to get some help...
If I take the exemple of my embedded application:
If I add #import "thredded"; in my application.scss file without setting config.assets.debug = true in my environments file. It is not importing the style...
If I do the same with config.assets.debug = true in my environments file.
It is working... I would like to understand how to make it works without config.assets.debug = true.
Is that a matter of precompile css file or something?
The problem was that I am under production environement, and I was not doin any:
rake assets:precompile RAILS_ENV=production
After that, my changes are applying just fine (still have my problems with double execution of my JS, but that's something else)...
Before asking my question, i read document configurigng Rails Applications
and i still don't know reason why my view cached is not working stably. In my case, after updating the codes in views, sometimes i don't need restart application server(Thin) and the views is reloaded with the modifications Seen that the controllers and models are not reloaded, so my app crashes ... Strange, this problem is not always there it's not stably. sometimes all is ok.
my config production mode like this:
...
# Code is not reloaded between requests
config.cache_classes = true
...
From the documentation, i learned that if i set true to config.cache_classes, i don't need to set true to config.action_view.cache_template_loading it will follow cache_classes configuring.
I think that cache_classes controls if all classes, modules and views templates will reload for each request. am i right ? any suggestion is welcome.
The first request to my rails app is extremely slow in all environments.
This should not be due different way of caching/loading gems. It was fine two hours ago and no major changes are made.
What I did the hours before I noticed my app turned slow:
I messed around in production.rb (NOT in development.rb): I was playing around with config.serve_static_assets = true
I did a bunch of tasks to diagnose why asset pipeline did not load my stylesheets and images in production (like rake assets:precompile RAILS_ENV=production and rake:clean assets:precompile).
Afterwards I obviously tried to undo all the changes I made, but for some reason my app is now slow in development, while it was perfectly fine before.
How can I fix this?
Thanks in advance :-)
UPDATE 1
When I send a request for localhost:3000, only after 12-13 seconds I receive:
Started GET "/" for ::1 at random time
Rendering behaving is normal. All requests after the first one are fine.
UPDATE 2
In an older version of my application I did the following:
Replace the old 'app'-folder with the newer one
Replace the old 'db'-files with the newer one
Replace the old 'config'-files with the newer one
Everything is running smoothly and still have no clue as to what was wrong in the first place. Please note that the version of the app from yesterday still runs slow, so this is not a non-rails related issue.
Answer
In production on localhost somehow my assets aren't served up (while they do appear in the public directory after a precompile).
In production.rb:
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
was changed to:
config.serve_static_files = true or even
config.serve_static_assets = true.
This also slows the first request down in a development environment apparently
I have this problem too, and i found bottleneck.
Problem in realization OpenSSL::Random.random_bytes on Windows (see this: https://github.com/rails/rails/issues/25805). It used for cookies.
I wrote this solution for my debug machine. But this is very dangerous and not must be used in production
module OpenSSL
module Random
def self.random_bytes(length)
::Random.new.bytes(length)
end
end
end
I have some iPhone client tests that run against my development rails server. The whole suite runs an order of magnitude faster if I turn on class caching in the Rails config. On the other hand, that slows down development when I'm not actually running the tests.
I want the test suite to hit an action at the beginning to turn on class caching and another action at the end to turn class caching off again.
Is this even possible? If so, how?
Not without some serious hacking. Rails goes to quite a lot of trouble to make sure your files are reloaded on every request (when cache_classes=false). The value of the cache_classes configuration variable is used by initializers in several places not the least of which being:
using require to load ruby files when cache_classes is true (meaning they are no longer reloadable)
setting up dispatcher callbacks to reaload the application on every request when cache_classes is false
You do have access to the value of the cache_classes variable, and you can even change it if you like:
Rails.configuration.cache_classes = true
But, this will have no effect on the running rails instance as the initializers where that value is used only run once when the rails app starts up.
What this means is this, unless you're prepared to invest some serious time and hacking effort you can't really avoid a restart of your server. So, what you need to look at is controlling this restart process via your test suite.
For example you can try to restart rails from within rails. This would allow you to define an action that your test suite can hit right before it begins executing (to restart the server in the right mode), and another action which the server can hit after all tests have finished, to restart everything with cache_classes set to what it used to be. You would control the value of cache classes via an environment variable like this post suggests.
It would still require a bit of work to set all of this up and get it to hang together, but this is probably your best bet if you want an 'auto-magical' solution.
I don't think doing what you suggest will work.
But I suggest you may be looking for the wrong solution.
If what you want is to access your development database from your iphone testing,
then why not add a new environment.
Add a new file config/environments/iphone_dev.rb
require File.dirname(__FILE__)+"/development.rb"
config.cache_classes = true
And in your database.yml (or mongoid.yml or whatever)
iphone_dev:
host: localhost
database: my_app_development
There is no reason the database cant be the same
Now just run rails server -eiphone_dev -p3001
You should have a server, almost the same as your dev server,
but running on a different port, with caching enabled.
In my rails app. I am using link_to_function to bring an ajax tabs in one page.Everything works fine in Moazilla and other browsers. But in IE the tabs are not loading only when the server is started in production mode(doesn't matter whether it's webrick or mongrel). In development mode everything is fine. So I figured out that the issue was with one line
config.cache_classes = true
in app/config/environments/production.rb
when I changed the above code to
config.cache_classes = false
everything works fine.
So I assume caching causes problem in Rails.
When I Googled about this I found many have the issues with caching.
So my question is
1) is there any other fix for this?
2) Does this fix (config.cache_classes = false) causes any performance issues. If then how to overcome that?
Any comments and suggestions are welcome.
Techno_log
cache_classes is setting that tells web server if it should reload whole app for each request. More precisely:
"Whether or not classes should be cached (set to false if you want application classes to be reloaded on each request)"
(from: http://api.rubyonrails.org/classes/Rails/Configuration.html)
Setting cache_classes to false will have big impact on your app performance.
However, your problem, most likely, is not related to this setting. I suggest that you take look at IE cache (i.e. try clearing out cache), maybe some caching headers you are setting when generating page, etc.
Also the fact that all other browsers get good response from server means that web server is generating good response.