I'm using Rails 7. I edit the files using Sublime Text on Windows 10. I have shared the folder where these files are located.
The Rails environment runs inside an Ubuntu Server VM using virtualbox. I use /etc/fstab to mount the cifs share containing the code base in Ubuntu. I have read and have all of these settings in development.rb:
config.cache_classes = false
config.reload_classes_only_on_change = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.cache_store = :null_store
config.public_file_server.headers = {
'Cache-Control' => "no-cache"
}
I access the development website through a VirtualBox host only network (i.e. 192.168.56.101:3000) using Firefox. I was having some trouble with files not update upon refresh, leading to some strange behavior. For anything other than views (controllers, models..etc) it seems to be working fine.
However, I'm now operating on the view templates and they are simply not updating, sometimes through many reloads of the page.
I have tried to make sure firefox is not caching them. Open the developer toolbar and disable HTTP caching.
I just opened Edge to see if it changes anything, and what do you know...even it's loading the old version of the view (without my changes). So Rails must be caching them, right? I did comment out the following lines:
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
# config.file_watcher = ActiveSupport::FileUpdateChecker
Something tells me there's an issue maybe with listen and the cifs share...so I have tried uncommenting out the above config line in development.rb...
config.file_watcher = ActiveSupport::FileUpdateChecker
Supposedly this makes the listen gem use polling instead.
It still doesn't reload the views when I change them.
--UPDATE-- It seems to be an issue with the samba share (regarding the listen gem?)
Learned that file_watcher only works if reload_classes_only_on_change is enabled:
config.reload_classes_only_on_change = true
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
OR
config.file_watcher = ActiveSupport::FileUpdateChecker
I moved the code base onto the Ubuntu VM in the home directory. A.) it's faster. B.) The views update properly when I used nano to change a view.html.erb
I setup a samba share on Ubuntu and connect to it from the windows host, so I can still use sublime text. Had to add this line to my global .git_config under C:\Users[My User]
[safe]
directory = %(prefix)///192.168.56.101/[VM_shared_folder]/[My App]
%(prefix) is literal, replace the rest with your setup
Hope this helps.
Related
I would like to install Redmine using the Bitnami stack. I have to build custom NEW pages in Redmine and perform some reporting - hence play around with some ROR code.
Can you please suggest me a good development process, as I will have to stop and restart Redmine's service upon every change.
Should I not use Bitnami for development (develop with a thin server first) and at the end merge/replace my files in Bitnami's Redmine folder?
You could switch to rails development environment. In this mode source code files are read by server upon every request.
Change database.yml, so it will have the same configuration options as in production mode. It is better to create separate database for development environment, but not necessary, since you're already developing in production.
Find your web-server configuration file and change in there environment to development.
There is other simpler way. Since (for now) you are interested only in source code updates per request, you can change only one parameter in rails configuration to do so. Open config/environments/production.rb and change line
config.cache_classes = true
to
config.cache_classes = false
Usually this option set to false in development with the following comment:
# 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.
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.
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
I'm running rails on a nfs shared folder in a vagrant box. While the server (thin/webrick) is running I'm editing files in my host. But I have to keep stopping and restarting the application server to see changes reflected in the webapp. Is this normal behaviour?
I go this issue on Vagrant box synchronising my folder with NFS.
I made a change in my application development configuration file (config/environments/development.rb), just adding this line config.reload_classes_only_on_change = false and it works.
Ensure that you have this config.cache_classes = false as well, I had it by default when I setup rails application (using version 4.1.5), because where I found that workaround (http://edgeguides.rubyonrails.org/configuring.html) says that config.reload_classes_only_on_chage = false is ignored if config.cache_classes is true
Another solution is use vagrant Rsync synchronise mechanism, which is available from version 1.5 and have some benefits, but for me it doesn't work because I run out of space if I have to make a copy of my workspace on each virtual machine that I have.
I have come into an existing Rails project which claims to use memcached. As a test I tried putting an object in the cache with
Rails.cache.write("gateway", #gateway)
Then retrieving it with
Rails.cache.read("gateway", #gateway)
however this returns nil, why is this?
This is in a development environment, memcached is installed and running and should be enabled by the entries config.cache_classes = true and config.action_controller.perform_caching = true.
Rails projects use memcached in various different ways but if you are working on a rails 3 project then I would suggest they may be using the 'dalli' gem which uses a memcached session store. So using the cache could instead be done something like this session[:gateway] = #gateway and the opposite #gateway = session[:gateway] the other way it is done is memcache.set('gateway',#gateway') and memcache.get('gateway')
Would be helpful to see the configuration code. check /config/initializers/session_store.rb for something like Rails.application.config.session_store :dalli_store ............
Also as said in the comments if you are in development caching may be turned off. Check your config/development.rb file for the following:
config.action_controller.perform_caching = false
the other thing is you need to have memcached installed on your os for linux this is sudo apt-get install memcached and can be checked by ps aux | grep memcache (this should show two proccesses the grep and memcache)
Update
Should also check out the rails caching guide