Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Heroku上全新Rails 5.2.1应用程序中的Javascript不';我不能正常工作_Ruby On Rails_Ruby_Heroku_Ruby On Rails 5.2 - Fatal编程技术网

Ruby on rails Heroku上全新Rails 5.2.1应用程序中的Javascript不';我不能正常工作

Ruby on rails Heroku上全新Rails 5.2.1应用程序中的Javascript不';我不能正常工作,ruby-on-rails,ruby,heroku,ruby-on-rails-5.2,Ruby On Rails,Ruby,Heroku,Ruby On Rails 5.2,我认为Heroku生产环境中Rails 5应用程序中的JavaScript文件存在一个大问题。不过,它在本地有效 我的配置: Windows: 10 Education Rails: 5.2.1 Ruby: 2.4.4p296 Heroku: heroku/7.7.7 win32-x64 node-v10.7.0 postgres: postgres (PostgreSQL) 10.3 现在,我将向您介绍我为确认它不起作用而采取的步骤,您可以自己尝试。最后,您将在

我认为Heroku生产环境中Rails 5应用程序中的JavaScript文件存在一个大问题。不过,它在本地有效

我的配置:

Windows:   10 Education
Rails:     5.2.1
Ruby:      2.4.4p296
Heroku:    heroku/7.7.7 win32-x64 node-v10.7.0
postgres:  postgres (PostgreSQL) 10.3
现在,我将向您介绍我为确认它不起作用而采取的步骤,您可以自己尝试。最后,您将在Heroku上获得bitbucket回购和应用程序的链接

步骤1:创建新的Rails 5应用程序并切换到根文件夹

> rails new my_app --database=postgresql
> cd my_app
> rails generate controller static_pages
> rails server
Started GET "/" for 127.0.0.1 at 2018-09-03 18:43:52 +0200
Processing by StaticPagesController#show as HTML
  Rendering static_pages/show.html.erb within layouts/application
  Rendered static_pages/show.html.erb within layouts/application (12.2ms)
Completed 200 OK in 504ms (Views: 486.7ms | ActiveRecord: 0.0ms)


Started DELETE "/logout" for 127.0.0.1 at 2018-09-03 18:43:57 +0200
Processing by StaticPagesController#destroy as HTML
  Parameters: {"authenticity_token"=>"10NHmV8N4tF3O0r/YYtKtKmHm3xthGjPAE51osb7L9skCM5ZoM2RoiCtZD4Crh9d69ndTOeNRMmIW28ipI/z9A=="}
  Rendering static_pages/destroy.html.erb within layouts/application
  Rendered static_pages/destroy.html.erb within layouts/application (0.0ms)
Completed 200 OK in 90ms (Views: 73.0ms | ActiveRecord: 0.0ms)
步骤2:生成控制器

> rails new my_app --database=postgresql
> cd my_app
> rails generate controller static_pages
> rails server
Started GET "/" for 127.0.0.1 at 2018-09-03 18:43:52 +0200
Processing by StaticPagesController#show as HTML
  Rendering static_pages/show.html.erb within layouts/application
  Rendered static_pages/show.html.erb within layouts/application (12.2ms)
Completed 200 OK in 504ms (Views: 486.7ms | ActiveRecord: 0.0ms)


Started DELETE "/logout" for 127.0.0.1 at 2018-09-03 18:43:57 +0200
Processing by StaticPagesController#destroy as HTML
  Parameters: {"authenticity_token"=>"10NHmV8N4tF3O0r/YYtKtKmHm3xthGjPAE51osb7L9skCM5ZoM2RoiCtZD4Crh9d69ndTOeNRMmIW28ipI/z9A=="}
  Rendering static_pages/destroy.html.erb within layouts/application
  Rendered static_pages/destroy.html.erb within layouts/application (0.0ms)
Completed 200 OK in 90ms (Views: 73.0ms | ActiveRecord: 0.0ms)
步骤3:编辑/app/controllers/static\u pages\u controller文件

class StaticPagesController < ApplicationController
  def show
  end

  def destroy
  end
end
Rails.application.routes.draw do
  root 'static_pages#show'
  get 'static_pages/show'
  delete '/logout', to: 'static_pages#destroy'
end
> rails db:create
Created database 'my_app_development'
Created database 'my_app_test'

> rails db:migrate
步骤5:编辑/config/routes.rb文件

class StaticPagesController < ApplicationController
  def show
  end

  def destroy
  end
end
Rails.application.routes.draw do
  root 'static_pages#show'
  get 'static_pages/show'
  delete '/logout', to: 'static_pages#destroy'
end
> rails db:create
Created database 'my_app_development'
Created database 'my_app_test'

> rails db:migrate
步骤6:检查路线

> rails routes
                   Prefix Verb   URI Pattern                                                                              Controller#Action
                     root GET    /                                                                                        staticpages#show
         staticpages_show GET    /staticpages/show(.:format)                                                              staticpages#show
                   logout DELETE /logout(.:format)                                                                        staticpages#destroy
       rails_service_blob GET    /rails/active_storage/blobs/:signed_id/*filename(.:format)                               active_storage/blobs#show
rails_blob_representation GET    /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
       rails_disk_service GET    /rails/active_storage/disk/:encoded_key/*filename(.:format)                              active_storage/disk#show
update_rails_disk_service PUT    /rails/active_storage/disk/:encoded_token(.:format)                                      active_storage/disk#update
     rails_direct_uploads POST   /rails/active_storage/direct_uploads(.:format)                                           active_storage/direct_uploads#create
步骤7:创建数据库并迁移

class StaticPagesController < ApplicationController
  def show
  end

  def destroy
  end
end
Rails.application.routes.draw do
  root 'static_pages#show'
  get 'static_pages/show'
  delete '/logout', to: 'static_pages#destroy'
end
> rails db:create
Created database 'my_app_development'
Created database 'my_app_test'

> rails db:migrate
步骤8:启动服务器

> rails new my_app --database=postgresql
> cd my_app
> rails generate controller static_pages
> rails server
Started GET "/" for 127.0.0.1 at 2018-09-03 18:43:52 +0200
Processing by StaticPagesController#show as HTML
  Rendering static_pages/show.html.erb within layouts/application
  Rendered static_pages/show.html.erb within layouts/application (12.2ms)
Completed 200 OK in 504ms (Views: 486.7ms | ActiveRecord: 0.0ms)


Started DELETE "/logout" for 127.0.0.1 at 2018-09-03 18:43:57 +0200
Processing by StaticPagesController#destroy as HTML
  Parameters: {"authenticity_token"=>"10NHmV8N4tF3O0r/YYtKtKmHm3xthGjPAE51osb7L9skCM5ZoM2RoiCtZD4Crh9d69ndTOeNRMmIW28ipI/z9A=="}
  Rendering static_pages/destroy.html.erb within layouts/application
  Rendered static_pages/destroy.html.erb within layouts/application (0.0ms)
Completed 200 OK in 90ms (Views: 73.0ms | ActiveRecord: 0.0ms)
步骤9:转到localhost:3000/并单击显示的链接。该链接起作用并向服务器发送删除操作

> rails new my_app --database=postgresql
> cd my_app
> rails generate controller static_pages
> rails server
Started GET "/" for 127.0.0.1 at 2018-09-03 18:43:52 +0200
Processing by StaticPagesController#show as HTML
  Rendering static_pages/show.html.erb within layouts/application
  Rendered static_pages/show.html.erb within layouts/application (12.2ms)
Completed 200 OK in 504ms (Views: 486.7ms | ActiveRecord: 0.0ms)


Started DELETE "/logout" for 127.0.0.1 at 2018-09-03 18:43:57 +0200
Processing by StaticPagesController#destroy as HTML
  Parameters: {"authenticity_token"=>"10NHmV8N4tF3O0r/YYtKtKmHm3xthGjPAE51osb7L9skCM5ZoM2RoiCtZD4Crh9d69ndTOeNRMmIW28ipI/z9A=="}
  Rendering static_pages/destroy.html.erb within layouts/application
  Rendered static_pages/destroy.html.erb within layouts/application (0.0ms)
Completed 200 OK in 90ms (Views: 73.0ms | ActiveRecord: 0.0ms)
步骤10:创建heroku应用程序(您必须在系统上登录heroku)

第11步:将您的工作推给Heroku

> git add -A
> git commit -m "init"
> git push --set-upstream heroku master
第12步:打开你的Heroku应用程序,像第9步那样操作,但失败了,因为JavaScript似乎无法正常工作

(...) Started GET "/" for 84.147.254.28 at 2018-09-03 16:47:44 +0000
(...) Processing by StaticPagesController#show as HTML
(...)   Rendering static_pages/show.html.erb within layouts/application
(...)   Rendered static_pages/show.html.erb within layouts/application (9.2ms)
(...) Completed 200 OK in 27ms (Views: 13.7ms)
.
.
. 
(...) Started GET "/logout" for 84.147.254.28 at 2018-09-03 16:48:05 +0000
(...) ActionController::RoutingError (No route matches [GET] "/logout"):
这要么是Rails上的一个明显错误,要么是Heroku方面的一个明显错误,因为我所做的只是创建一个新的Rails应用程序,并更改了路由,生成了一个控制器,为控制器操作创建了两个视图

如果您想查看应用程序和部署到heroku的应用程序的所有源代码,请访问以下链接

您可以在此处查看源代码:

这里的应用程序:

是否有其他人在Rails和Heroku方面有这样的困难,或者我可以做些什么来让它工作


编辑:通过删除不必要的日志信息和时间戳,使步骤12的输出更加清晰

问题是
duktape
gem。这是一个Javascript引擎,在Rails世界中没有广泛使用,但默认情况下包含在新的Windows Rails安装中,因为它是唯一在Windows中实际工作的引擎之一。(如果您现在还没有弄清楚,那么Rails和windows开发人员就不多了:)

我不认为Heroku对它有很好的支持,所以当它启动引擎时,JS会默默地编译失败。如果您查看生产环境中的
application.js
文件,您将看到一堆
NaN:“选择[数据远程]、输入[数据远程]、文本区域[数据远程]”,在顶部,您将看到类似于
inputChangeSelector:“选择[数据远程]、输入[数据远程]、文本区域[数据远程]”`

如果您想让事情正常进行,请将
Duktape
gem从当前位置移到Gemfile、bundle和redeploy的
development
部分(您现在可以避免在主Gemfile中使用JS编译器)


我也会向Heroku开一张罚单。一般来说,他们会警告你类似这样的常见配置问题,但当我尝试部署你的应用程序时,我没有收到这样的警告。我可以想象,很多用户都没有收到这样的警告。

我解决了我的问题:是
丑陋的
宝石导致了问题,因为它工作不正常。我是j作为一个初学者,回顾一下这个gem应该是我需要检查的第一件事,因为它进行了JS压缩

现在JS运行得非常好。下面是我在
GemFile
中所做的更改,以使其正常工作:

uglifier
gem版本是
4.1.18
,在生产环境中导致此JS错误


希望这有助于其他人在Heroku上记录他们的JS错误

你从哪里得知错误与javascript有关?它在本地工作吗?是的,它在本地工作(如步骤9所示),正如我所说,它在生产模式中失败,但我编辑以使其更清晰。我知道它的javascript,因为应用程序需要“rails ujs”为了工作,没有它,它甚至在本地也不工作,我在生产模式下会出现JavaScript错误,而在本地控制台中根本没有。下面是我关于这个问题的另一个思路,让我澄清一下:如果你想在你的windows机上完成这些最小的步骤,并告诉我你是否可以重现错误,我将不胜感激rails在这一点上有问题吗?您是否尝试过查看浏览器控制台并实际尝试诊断javascript错误?我照您所说的做了。将duktape放入开发组并推送到Heroku。有一行内容说明
删除duktape(2.0.1.0)
在部署时。在尝试创建一个全新的Heroku应用程序时,仍然有很多NAN和错误,链接不起作用。我有一种预感,在第一次部署时,有一些部署设置被锁定。我也会联系Heroku支持人员,他们可能会提供更多帮助。我解决了这个问题,这是由
丑陋的人造成的我想在生产中有缺陷的宝石