简体   繁体   English

为什么必须重新启动apache才能正确刷新浏览器中的Ruby on Rails视图?

[英]Why do I have to restart apache to properly refresh a Ruby on Rails view in the browser?

I am trying to learn a bit of Ruby. 我正在尝试学习一些Ruby。 I've installed Ruby on my Ubuntu machine and I am using apache. 我已经在Ubuntu机器上安装了Ruby,并且正在使用apache。 Everything works fine except to refresh a view I have to restart apache in the console and then hit ctrl-r, just pressing ctrl-r won't refresh the browser. 一切正常,除了刷新视图外,我必须在控制台中重新启动apache,然后按ctrl-r,仅按ctrl-r不会刷新浏览器。

Apparently there's some caching going on, but does it have to be that way ie is it inherent to Ruby on Rails? 显然有一些缓存正在进行,但是是否一定要这样,即Ruby on Rails是否固有? I tried googling on this but it seems the only answer is to install some long-winded routine. 我尝试对此进行谷歌搜索,但似乎唯一的答案是安装一些冗长的例程。 For developing it seems like quite the tedious way to go. 对于开发而言,这似乎是很乏味的方法。

Apache's a perfectly good choice for development. Apache是​​开发的绝佳选择。

Just install Passenger (mod_rails)...and follow the instructions... 只需安装旅客(mod_rails)...并按照说明进行操作...

I set it up for each site so that /etc/hosts contains 我为每个站点设置了它,以便/ etc / hosts包含

127.0.0.1 myapp

I use Apache virtual hosts with an entry like so - in /etc/apache2/sites-available/myapp 我在这样的条目中使用Apache虚拟主机-在/ etc / apache2 / sites-available / myapp中

<VirtualHost *:80>
  ServerName myapp
  DocumentRoot /path/to/myapp/public
  RailsEnv development
  RailsAllowModRewrite off
    <directory "/path/to/myapp/public">
      Order allow,deny
      Allow from all
    </directory>
</VirtualHost>

Enable and restart 启用并重新启动

sudo a2ensite myapp
sudo /etc/init.d/apache2 restart

That way, there's no running script/server ... it's just always running in dev mode - just point your browser to http://myapp 这样,就没有正在运行的脚本/服务器...它始终以开发人员模式运行-只需将浏览器指向http:// myapp

Don't use apache for development mode. 不要将apache用于开发模式。 Use script/server and install the mongrel gem (sudo gem install mongrel). 使用脚本/服务器并安装mongrel gem(sudo gem install mongrel)。 Mongrel is faster than WEBrick and dumps the development log to the console in which it runs. Mongrel比WEBrick快,并将开发日志转储到运行它的控制台中。 It makes development decent. 它使发展得体。

Apache is not a good choice for development in cases like Rails, because you will indeed need to restart the server every time you change code. 在诸如Rails这样的情况下,Apache并不是一个很好的开发选择,因为您确实需要在每次更改代码时都重新启动服务器。 Rails ships with its own development server that you can start by executing (IIRC) script/server. Rails附带了自己的开发服务器,您可以通过执行(IIRC)脚本/服务器来启动。 It's much more suitable for development, as it needn't be restarted after every little change. 它更适合于开发,因为它不需要每次更改后都重新启动。

I'm using Apache with Passenger (aka modrails) for development purposes, and it works fine here. 我将Apache与Passenger(aka modrails)一起用于开发目的,在这里工作正常。 Just make sure to use Rails in development mode by setting "RailsEnv development" in your httpd.conf. 只需通过在httpd.conf中设置“ RailsEnv开发”来确保在开发模式下使用Rails。

I use Apache with mod_fcgid. 我将Apache与mod_fcgid一起使用。 I found that going 我发现

$ touch ${MYAPP}/tmp/restart.txt

every time I want the app reloaded works for me. 每次我希望重新加载应用程序时,对我来说都是有效的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM