在localhost上开发测试代码时出现Errno :: EACCES错误

时间:2021-08-05 18:22:33

Get this error when running this code:

运行此代码时出现此错误:

<% content_for :game do %>
<% gamefolder = Dir.open(`#{Rails.root}/public/browserGames/#{@browserGame.slug}`) %>
<% gameFolder.each do |file| %>
  <% if file.match?(/.js/) %>
    <script src=<%= `#{Rails.root}/public/browserGames/#{@browserGame.slug}` + file %>></script>
  <% end %>
<% end %>

It stops me on line 2 and gives the Errno::EACCES error. I am simply running this on localhost in development mode. Wanting to make sure everything works before I try to deploy and find similar issues.

它阻止了我在第2行,并给出了Errno :: EACCES错误。我只是在开发模式下在localhost上运行它。在尝试部署和查找类似问题之前,要确保一切正常。

What I am trying to accomplish with this code is to load the js files for the specific game trying to be played in the window.

我想用这段代码完成的是加载试图在窗口中播放的特定游戏的js文件。

I am also open to trying other ways of achieving the goal, but I have different games on here and want to make sure I am only loading the specific files for the selected game.

我也愿意尝试其他方法来实现目标,但我在这里有不同的游戏,并希望确保我只加载所选游戏的特定文件。

Any help is greatly appreciated.

任何帮助是极大的赞赏。

1 个解决方案

#1


0  

Use

Dir["#{Rails.root}/public/browserGames/test/*.js"]

instead of opening open for dir. and use <script src="<%= file %>"></script>

而不是为dir打开。并使用

#1


0  

Use

Dir["#{Rails.root}/public/browserGames/test/*.js"]

instead of opening open for dir. and use <script src="<%= file %>"></script>

而不是为dir打开。并使用