Possible to get Rails 4 working on Windows?

£可爱£侵袭症+ 提交于 2019-12-29 04:48:07

问题


I'm working on a Rails 4 (using the release candidate) project and now need to collaborate with someone on a Windows machine. I can't even get a basic webpage to come up, however :(. It was quite a pain even installing sqlite3 using Ruby 2.0. Now, when I try to get a webpage up (I just created a dummy /home/index controller and view), I get this error:

Showing C:/Users/me/RubymineProjects/test_project/app/views/layouts/application.html.erb where line #6 raised:

  (in C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/turbolinks-1.1.1/lib/assets/javascripts/turbolinks.js.coffee)

Extracted source (around line #6):
3  <head>
4    <title>TestProject</title>
5    <%= stylesheet_link_tag    "application", media: "all", "data-turbolinks-track" => true %>
6    <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
7    <%= csrf_meta_tags %>
8  </head>
9  <body>

Is Rails 4 just not ready for Windows yet? Using Ruby 2.0.0p195.

UPDATE: As per @szines request, here's the webpage output for

http://localhost:3000/rails/info/properties:
Ruby version    2.0.0 (x64-mingw32)
RubyGems version    2.0.3
Rack version    1.5
Rails version   4.0.0.rc1
JavaScript Runtime  JScript
Active Record version   4.0.0.rc1
Action Pack version 4.0.0.rc1
Action Mailer version   4.0.0.rc1
Active Support version  4.0.0.rc1
Middleware  
ActionDispatch::Static
Rack::Lock
#<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x000000036b85c0>
Rack::Runtime
Rack::MethodOverride
ActionDispatch::RequestId
Rails::Rack::Logger
ActionDispatch::ShowExceptions
ActionDispatch::DebugExceptions
ActionDispatch::RemoteIp
ActionDispatch::Reloader
ActionDispatch::Callbacks
ActiveRecord::Migration::CheckPending
ActiveRecord::ConnectionAdapters::ConnectionManagement
ActiveRecord::QueryCache
ActionDispatch::Cookies
ActionDispatch::Session::CookieStore
ActionDispatch::Flash
ActionDispatch::ParamsParser
Rack::Head
Rack::ConditionalGet
Rack::ETag
Warden::Manager
Application root    C:/Users/me/RubymineProjects/test_project
Environment development
Database adapter    sqlite3
Database schema version 20130523073322

回答1:


<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>

Change this to :

<%= stylesheet_link_tag "defaults", media: "all", "data-turbolinks-track" => true %>

It should work.

It will be great if someone can provide explanation for this.

More info:

ExecJS::RuntimeError in Users#index (RoR)

ExecJS and could not find a JavaScript runtime




回答2:


Just install node.js and the problem will gone.

Explanation: If you'll try to precompile assets, you'll get the following trace:

(in C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/turbolinks-1.3.0/lib/assets/javascripts/turbolinks.js.coffee)
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:142:in `exec_runtime'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:28:in `block in exec'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:41:in `compile_to_tempfile'
...

As you can see, there is a problem with ExecJS. ExecJS lets you run JavaScript code from Ruby and it requires one of the JS interpreters to be installed on your system. Here's a list of supported interpreters. Usually, you can use therubyracer which is just V8 but there are problems with compiling V8 under the windows. So you can choose another option - NodeJS. ExecJS will use it automatically when you'll install NodeJS and add it to your PATH.




回答3:


changing following line

<%= javascript_include_tag "application", "data-turbolinks-track" => true %>

to

<%= javascript_include_tag "defaults", "data-turbolinks-track" => true %>

works.

OR

you can install node.js




回答4:


The actual solution for getting Turbolinks to work on Windows 8 x64 is posted at ExecJS::RuntimeError on Windows trying to follow rubytutorial, option 3.




回答5:


I have been facing this problem for a while and it's that on windows jquery and coffee script are not functional in their latest update and finally i found this wonderful method that worked perfectly without the need to download node or escape //require tree. So all you need is configure the settings in your runtimes.rb which lives in execjs to be like this- you will find this part with few differences fix them and you'll be good to go.

JScript = ExternalRuntime.new(
:name        => "JScript",
:command     => "cscript //E:jscript //Nologo",
:runner_path => ExecJS.root + "/support/jscript_runner.js",
:encoding    => 'UTF-8' # CScript with //U returns UTF-16LE

You can watch this video for detailed solution. https://www.youtube.com/watch?v=N5i94L17KPo



来源:https://stackoverflow.com/questions/16739581/possible-to-get-rails-4-working-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!