Altering the files of a rails application without restarting the server - ruby-on-rails

I have a rails application running on production environment on a remote server. Though the application is ready for use it is far from finished so it is going to be subject to changes in views, controllers and css files.
Is there a way to update one of those files and make the server aware of the change without having to stop it? I tried cleaning the caches on both server and browser side in order to force the application to regenerate them with no success.
In the production.rb file I have these options
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
config.log_level = :fatal
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
Thank you.

Have you considered versioning with Git? In a typical rails deployment, you would use something like git to version your software and then deploy with something like Capistrano so that you can push small changes up to a place like Github and then pull those changes in to your app via capistrano. There's a really great tutorial on how to do this on railscasts by Ryan Bates. Here's a link to Railscast #335.

Related

Rails ActionController::Live without restart server on developpement

I'm using SSE (Server Sent Event) in rails with the ActionController::Live of rails 4.
It's working fine. But in developpement, I have to defined my configuration like this :
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
I have to restart the puma server each time I do a modification.
Is there a way to do that without restart ?
Your configuration of config.cache_classes = true explicitly disables hot-reloading of classes when they change. You'll have to set that to false in development to avoid server restarts between changes.

Rails 4 asset pipline slow

I have read dozens of posts all over the internet about this but mostly for Rails 3.
For some reason, it takes 35 seconds to load a page with a total of 34 assets in development.
I have done the following:
Set config.assets.debug = false in development.rb, but this only cuts it down to 30 seconds,
reloaded the page multiple times, but each load is just as slow,
precompiled the assets manually (although this seems to only applies in production),
looked for something like rails-dev-boost (https://github.com/thedarkone/rails-dev-boost) but cannot find anything for rails 4.
I'm developing on an ubuntu box using vagrant (https://github.com/rails/rails-dev-box). The host machine is the fastest, new MacBook Pro.
I'm almost going to throw out the asset pipeline altogether and compile the assets myself. I cannot wait 35 seconds every time I need to reload the page.
Any help on this is appreciated.
development.rb:
MyProject::Application.configure do
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = false
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end
Edit
I think the issue is the VM. I installed ruby on my Mac using homebrew and ran the same project with the exact configuration and it loads in under 1 second. I'm not sure what the problem is.
The issue is probably with your shared_folder on Vagrant box, which can be fixed by using rsync:
Install rync on your mac: brew install rsync
In your Vagrant file, add type: "rsync" to your synced_folder: config.vm.synced_folder "[path to host folder]", "[path to guest folder]", type: "rsync"
I was experiencing 20-25 second page load times, and once I added rsync, my pages were loading in under a second. Since the shared_folder by default is only pointing to your code, it essentially has to load those files to the VM each time the page loads.
adding gem 'rack-mini-profiler' or less-easy-to-use gem 'ruby-prof' can help to find what renders slow
i have around fifty heavy js|css files and it renders pretty fast in development environment, so it is very unlikely that problem core in assets pipeline itself

Rails assets are cached even in Development

Here is my 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 web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.assets.digest = true
config.serve_static_assets = false
For some reason even in the development environment my CSS files are being cached and I can't figure out why
Was having similar issue: Javascript files were cached by the rails server
Solution (as mentioned by TheIrishGuy):
Stop Rails Server
$rake tmp:cache:clear
Start Rails Server
Crtl+F5 in the browser
Did you precompile any assets? If so check the public assets folder and remove.
Try clearing /tmp/cache/assets
Make sure the browser isn't caching the application.css, force refresh etc

Rails compiles assets both with and without md5 hash, why?

I'm relatively new to RoR and I'm curious about why Rails compiles assets both with and without md5 hash for production?
I run bundle exec rake assets:clean then bundle exec rake assets:precompile
My production.rb file:
MyApp::Application.configure do
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
config.assets.precompile += %w(tos.js, tos.css)
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
end
My application works with files with hashes in their names and it's the way it should be in my case :)
So I have two questions here:
1) Why is it happening when compiled?
Rails compiles assets both with and without md5 hash for production
2) What are these files (without hashes) for?
Maybe I don't get something, so please could someone explain.
The reason it does it is so that you can access the files without knowing the MD5 fingerprint (for example in a non-rails application, or a file within the rails app which isn't compiled or run by the rails stack (e.g. a 500/502 status error page). In this case you would have to compile the assets then change the css/js links in the static HTML files each time you updated the code (thus causing a change in the MD5 hash).
So instead rails produces 2 copies of each asset file, one with the fingerprint in the filename, the other without (e.g. application-731bc240b0e8dbe7f2e6783811d2151a.css, and application.css). The fingerprinted version is obviously preferred (see 'what is fingerprinting and why should I care' in the rails asset pipeline guide). But the non-digested version is there as a fallback.
As a final thought on the matter I'd take a read of the following pull request to the rails git repo: https://github.com/rails/rails/pull/5379 where they are discussing the pros and cons of the non-digested filenames, and the possibility of being able to turn off compilation of them.
HTH

Rails 3.1 Production - Javascript is missing .js endings on deployment

I've just made my Rails app and deployed it to Heroku. A very weird thing happened in the process though. Half of my javascript-files are missing their endings (.js). I have absolutely no idea why this is.I've searched far and wide, but I don't seem to find an answer.
My production-config looks like this:
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
# Generate digests for assets URLs
config.assets.digest = true
config.assets.precompile << '*.js'
Any suggestions?
Posted this other similar question 1 hour ago (http://stackoverflow.com/questions/9049023/rails-3-1-production-javascript-loads-but-doesnt-execute). Sorry for the spamming.
Does this help? You didn't show where your js files are included. If they have dots in the name, apparently you need to tell Rails.
asset:precompile for .js files? rails 3.1

Resources