gpt4 book ai didi

ruby-on-rails - 在 AWS elastic beanstalk 上部署 Rails - 静态 Assets 路由不起作用

转载 作者:数据小太阳 更新时间:2023-10-29 07:39:27 24 4
gpt4 key购买 nike

我通过亚马逊的 eb 工具在 AWS elastic beanstalk 上安装了我的 Rails 应用程序。在 elastic beanstalk 上,我使用它的默认负载均衡器,并使用 ruby​​ 2.0 运行 ubuntu 64bit。

我遇到了两个主要问题:

1) 根路由不工作。

  • 在我的 config/routes.rb 中,我试过:

    root 'controller#action
    root :to => 'controller#action'
    root to: 'controller#action'

    并发现它们都不起作用。服务器给我一个错误说:

    Invalid route name, already in use: 'root' (ArgumentError)

  • 我猜 Rail 的默认 root=>public/index.html 和我自己在 config/routes.rb 中的路由之间存在某种冲突?所以我创建了 public/index.html 并且根 url '/' 现在服务于 public/index.html。我想找出一种方法让它以“Rails”方式工作,根 url 路由到 controller#action。

2) 未提供静态 Assets 。

有人知道这些问题的解决方案吗?

提前致谢!

=========================编辑===================== ======

我将 Amazon 64 位 Linux 与 Passenger Standalone 一起使用

最佳答案

尝试以下操作:

config/routes.rb

Rails.application.routes.draw do
root 'home#index'
end

删除或注释掉所有'/'的定义(包括获取'/',匹配'/'等)

app/controllers/home_controller.rb

class HomeController < ApplicationController

def index
render 'index'
end

end

app/views/home/index.html.erb

<h1>HELLO WORLD.</h1>

并确保删除 public/index.html

关于ruby-on-rails - 在 AWS elastic beanstalk 上部署 Rails - 静态 Assets 路由不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24644254/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com