2014-07-19 15 views
12

Tôi muốn xem các thay đổi trực tiếp trong trình duyệt nếu tôi chỉnh sửa tệp .scss hoặc .erb trong Trình chỉnh sửa văn bản trong dự án Rails 4 + Ruby 2.0.Làm cách nào để tải lại trực tiếp bằng ứng dụng Rails 4 và Ruby 2.0?

Tôi đã thử Guard và Guard-live-reload, nhưng nó ném lỗi sau đây.

22:58:04 - ERROR - Could not load 'guard/rspec' or find class Guard::Rspec 
22:58:04 - ERROR - /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/plugin_util.rb:100:in `require' 
> [#] /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/plugin_util.rb:100:in `plugin_class' 
> [#] /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/plugin_util.rb:57:in `initialize_plugin' 
> [#] /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard.rb:167:in `add_plugin' 
> [#] /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/dsl.rb:174:in `block in guard' 
> [#] /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/dsl.rb:173:in `each' 
> [#] /home/jitendra/.rvm/gems/[email protected]/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/[email protected]/gems/guard-2.6.1/lib/guard/guardfile/evaluator.rb:97:in `instance_eval' 
> [#] /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/guardfile/evaluator.rb:97:in `_instance_eval_guardfile' 
> [#] /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/guardfile/evaluator.rb:37:in `evaluate_guardfile' 
> [#] /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/setuper.rb:148:in `evaluate_guardfile' 
> [#] /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/setuper.rb:64:in `setup' 
> [#] /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/commander.rb:24:in `start' 
> [#] /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/cli.rb:107:in `start' 
> [#] /home/jitendra/.rvm/gems/[email protected]/gems/thor-0.19.1/lib/thor/command.rb:27:in `run' 
> [#] /home/jitendra/.rvm/gems/[email protected]/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command' 
> [#] /home/jitendra/.rvm/gems/[email protected]/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch' 
> [#] /home/jitendra/.rvm/gems/[email protected]/gems/thor-0.19.1/lib/thor/base.rb:440:in `start' 
> [#] /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/bin/guard:6:in `<top (required)>' 
> [#] /home/jitendra/.rvm/gems/[email protected]/bin/guard:23:in `load' 
> [#] /home/jitendra/.rvm/gems/[email protected]/bin/guard:23:in `<main>' 
> [#] /home/jitendra/.rvm/gems/[email protected]/bin/ruby_executable_hooks:15:in `eval' 
> [#] /home/jitendra/.rvm/gems/[email protected]/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/[email protected]/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/[email protected]/gems/guard-2.6.1/lib/guard.rb:167:in `add_plugin' 
    from /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/dsl.rb:174:in `block in guard' 
    from /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/dsl.rb:173:in `each' 
    from /home/jitendra/.rvm/gems/[email protected]/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/[email protected]/gems/guard-2.6.1/lib/guard/guardfile/evaluator.rb:97:in `instance_eval' 
    from /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/guardfile/evaluator.rb:97:in `_instance_eval_guardfile' 
    from /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/guardfile/evaluator.rb:37:in `evaluate_guardfile' 
    from /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/setuper.rb:148:in `evaluate_guardfile' 
    from /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/setuper.rb:64:in `setup' 
    from /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/commander.rb:24:in `start' 
    from /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/lib/guard/cli.rb:107:in `start' 
    from /home/jitendra/.rvm/gems/[email protected]/gems/thor-0.19.1/lib/thor/command.rb:27:in `run' 
    from /home/jitendra/.rvm/gems/[email protected]/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command' 
    from /home/jitendra/.rvm/gems/[email protected]/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch' 
    from /home/jitendra/.rvm/gems/[email protected]/gems/thor-0.19.1/lib/thor/base.rb:440:in `start' 
    from /home/jitendra/.rvm/gems/[email protected]/gems/guard-2.6.1/bin/guard:6:in `<top (required)>' 
    from /home/jitendra/.rvm/gems/[email protected]/bin/guard:23:in `load' 
    from /home/jitendra/.rvm/gems/[email protected]/bin/guard:23:in `<main>' 
    from /home/jitendra/.rvm/gems/[email protected]/bin/ruby_executable_hooks:15:in `eval' 
    from /home/jitendra/.rvm/gems/[email protected]/bin/ruby_executable_hooks:15:in `<main>' 

Trả lời

17

Đây là cách tôi làm việc với livereload:

1.) Lấy gem

Trong Gemfile của bạn:

group :development do 
    gem 'guard-livereload', require: false 
end 

2.)guard init livereload, nào sẽ tạo một số Guardfile tại gốc của Ứng dụng của bạn.

3.) Mở Guardfile của bạn nó sẽ giống như thế này (Chỉ cần Guard-Livereload, nếu bạn chạy các plugin bảo vệ khác chắc chắn rằng họ đang dưới 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.) Lấy Chrome App Livereload từ Chrome Web Store

5.) Khởi động lại máy chủ của bạn và mở một tab riêng biệt và loại->guard

6.) Trong Trình duyệt của bạn nhấn nút livereload và nó sẽ liên kết nó (trình duyệt kết nối trong Tab Guard)

tôi đã viết một cách sâu đậm cho người kia có thể vấp ngã khi cùng một câu hỏi. Đối với trường hợp cụ thể của bạn, hãy đọc # 3. Mở guardfile của bạn và chắc chắn rằng ganeload được gọi là đầu tiên.

Go xem Railscast #264 Guard

Khi làm việc với SSL, livereload không như thế khá tốt.

Rack-Livereload là một ít đá quý gọn gàng mà bạn có thể thêm vào dự án của mình để khắc phục các sự cố SSL. Đá quý chèn một mảnh hoặc phần mềm trung gian Rack và về cơ bản kết nối với ứng dụng tải gan để phục vụ lên javascript thông qua máy chủ Rails hiện có (và SSL được kích hoạt).

+0

23:40:12 - INFO - LiveReload đang chờ trình duyệt kết nối. –

+0

Tuyệt vời, nhấn nút Ganeload trên trình duyệt của bạn. –

+0

ok đây là đầu ra sau khi tôi thực hiện thay đổi trong .erb tập tin http://pastebin.com/SeLfx7qr cũng trang không làm mới –

Các vấn đề liên quan