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.
Related
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.
I am using the latest version of Craft CMS with 'useProjectConfigFile' enabled.
My development process involves creating/updating Craft settings locally, committing this to Git and then deploying to production. The changes are then sync'd the production Craft CMS fine.
For some reason I have a Global set in the production CMS that doesn't exist on my local version.
Should this be removed when the config file is sync'd up? Any reason why it isn't not syncing correctly?
You have to sync the configs by hand in the cp of craft cms. Then they will be applyed.
You could apply project config settings automatically
during deployment via the craft console commands
./craft project-config/apply
Otherwise you have to manualiy apply the new settings in the craft control panel:
You can try rebuilding the config with the help of this command.
project-config/rebuild
It rebuilds the config.
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.
a) I'm a ruby in rails beginner developer, and I use windows 7 machine as developement environment...
b) With VirtualBox I just installed, inside the Windows 7 "host", a Linux ubuntu sever "guest", just to run the rails DEVELOPMENT environment ALSO in the linux machine.
c) To do that I configured a virtualbox SHARED FOLDER:
let say I have this shared folder on the host machine (window):
c:\rails\esamiAnatomia
and mounted it on the linux embedded server:
/home/solyaris/host/esamianatomia
d) In this exptended "developement environment" I would like to edit source files with my preferred visual editor on windows (sublime text) and run rails server on linux.
The problem concern database.yml configuration file:
/home/solyaris/host/esamianatomia/config/database.yml
because on Windows I have a database (postgresql) responding port 5433, with specific username/password
but in linux database respond to port 5432, etc.
Questions:
1) It's that "arcgitectural solution ok ? (I mean: developing/editing from a windows 7 host, but running rails server of the linux guest server);
2) There is a way to change/configure database.yml on the fly (I mean: using two different database.yml files: one for the linux machine and anotherone for the window machine) ?
thanks a lot
giorgio
You can technically accomplish 2 if you're not afraid to play around with the guts of Rails. As with any solution that has you accessing internal rails components this may stop working at any time, but fortunately this part of the API is not likely to change often, if ever. Still, use this at your own risk.
Here's how I do it on my projects. First modify your application as follows:
# config/application.rb:
# After require 'rails/all'
require_relative 'db_override'
Then create this new file:
# config/db_override.rb:
case Socket.gethostname
when 'host1'
$db_config = 'config/host1_database.yml'
when 'host2'
$db_config = 'config/host2_database.yml'
else
$db_config = nil # Use the default config/database.yml
end
if $db_config
class DBConfigSelect < Rails::Railtie
initializer "db_config_select", before: "active_record.initialize_database" do
puts "Using custom DB configuration: #{$db_config}"
# Get the existing path configuration
cur_paths = Rails.application.config.paths['config/database'].instance_variable_get :#paths
# Override the default config sources
cur_paths.shift
cur_paths.push $db_config
end
end
end
What you are describing is pretty much the setup that Vagrant is offering, so yeah, you are doing fine, everyone else is also doing it but they didn't set it up themselves (and by that probably get some really nice addons as well, you should take a look at Vagrant).
For your second question: no. Not on the fly. Rails loads the database.yml end then connects to the database with that. When you change it while your Rails server is running, the changes won't get noticed. What you can do however is setup a new environment for your two different machines. Then you can switch between the different environments and depending on the environment, one or the other database gets accessed.
I have an replica of the live app that is deployed on the server. I have made some changes: like inserted 2 css and js files in /public directory that serves my assets and included in the views where they are required .It is working fine on my Local machine but when I pushed the changes to the server it is not reflecting over there. I am Using Nginx and I have tried restarting it as well but it didn't help either.
As I am new to NGINX and the App is deployed on a centos I dont know how it works.
I already have precompiled assets, So I don't know how to make it run. I have tried
Clearing the cache from tmp directory but didn't work.
I have set my
config.serve_static_assets = false
in my production.rb and tried restarting but didn't work either
Any help ??
Your views are cached in webserver workers. Have you restarted your web workers?