如果我在Rails 4
Ruby 2.0项目的文本编辑器中编辑.scss或.erb文件,我想在浏览器中看到实时更改.
我试过Guard和Guard-live-reload,但是它会抛出以下错误.
22:58:04 - ERROR - Could not load 'guard/rspec' or find class Guard::Rspec 22:58:04 - ERROR - /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/plugin_util.rb:100:in `require' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/plugin_util.rb:100:in `plugin_class' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/plugin_util.rb:57:in `initialize_plugin' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard.rb:167:in `add_plugin' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/dsl.rb:174:in `block in guard' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/dsl.rb:173:in `each' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/dsl.rb:173:in `guard' > [#] /home/jitendra/milaap-webapp/Guardfile:4:in `_instance_eval_guardfile' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/guardfile/evaluator.rb:97:in `instance_eval' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/guardfile/evaluator.rb:97:in `_instance_eval_guardfile' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/guardfile/evaluator.rb:37:in `evaluate_guardfile' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/setuper.rb:148:in `evaluate_guardfile' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/setuper.rb:64:in `setup' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/commander.rb:24:in `start' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/cli.rb:107:in `start' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/thor-0.19.1/lib/thor/command.rb:27:in `run' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/thor-0.19.1/lib/thor/base.rb:440:in `start' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/bin/guard:6:in `<top (required)>' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/bin/guard:23:in `load' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/bin/guard:23:in `<main>' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/bin/ruby_executable_hooks:15:in `eval' > [#] /home/jitendra/.rvm/gems/ruby-2.1.1@global/bin/ruby_executable_hooks:15:in `<main>' 22:58:04 - ERROR - Invalid Guardfile,original error is: > [#] undefined method `superclass' for nil:NilClass /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/plugin_util.rb:57:in `initialize_plugin': undefined method `superclass' for nil:NilClass (NoMethodError) from /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard.rb:167:in `add_plugin' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/dsl.rb:174:in `block in guard' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/dsl.rb:173:in `each' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/dsl.rb:173:in `guard' from /home/jitendra/milaap-webapp/Guardfile:4:in `_instance_eval_guardfile' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/guardfile/evaluator.rb:97:in `instance_eval' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/guardfile/evaluator.rb:97:in `_instance_eval_guardfile' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/guardfile/evaluator.rb:37:in `evaluate_guardfile' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/setuper.rb:148:in `evaluate_guardfile' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/setuper.rb:64:in `setup' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/commander.rb:24:in `start' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/lib/guard/cli.rb:107:in `start' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/thor-0.19.1/lib/thor/command.rb:27:in `run' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/thor-0.19.1/lib/thor/base.rb:440:in `start' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/gems/guard-2.6.1/bin/guard:6:in `<top (required)>' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/bin/guard:23:in `load' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/bin/guard:23:in `<main>' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/bin/ruby_executable_hooks:15:in `eval' from /home/jitendra/.rvm/gems/ruby-2.1.1@global/bin/ruby_executable_hooks:15:in `<main>'
解决方法
@H_403_9@ 这是我如何使用livereload:1)获得gem
在你的宝石文件中:
group :development do gem 'guard-livereload',require: false end
2.)保护init livereload,这将在你的应用程序的根目录下生成一个Guardfile.
3.打开你的Guardfile应该看起来像这样(只要Guard-Livereload,如果你运行其他防护插件,确保它们在livereload之下).
guard 'livereload' do watch(%r{app/views/.+\.(erb)$}) watch(%r{app/helpers/.+\.rb}) watch(%r{public/.+\.(css|js|html)}) watch(%r{config/locales/.+\.yml}) watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html|png|jpg))).*}) { |m| "/assets/#{m[3]}" } end
4.)从Chrome Web Store获取Livereload Chrome应用程序
5.)重新启动服务器并打开一个单独的选项卡,然后键入 – >守卫
6.)在浏览器中,pushreload按钮应该链接它(浏览器连接在Guard选项卡中)
我写的很广泛的其他人可能会绊倒同样的问题.对于您的具体情况,请阅读#3.打开你的保护文件,并确保首先调用livereload.
Go watch the 07002
使用SSL时,livereload并不是很好.
Rack-Livereload是一个整洁的小宝石,您可以添加到您的项目,以解决SSL问题.宝石插入一个或Rack中间件,并基本上连接到livereload应用程序,以通过现有(和启用SSL)的Rails服务器来提供JavaScript.