简体   繁体   English

在AWS弹性beanstalk上部署Rails - 静态资产路由无法正常工作

[英]Deploying Rails on AWS elastic beanstalk - Static Asset routing not working

I put up my rails application on AWS elastic beanstalk through Amazon's eb tool. 我通过亚马逊的eb工具将我的rails应用程序放在AWS弹性beanstalk上。 On elastic beanstalk, I'm using its default load balancer, and am running ubuntu 64bit with ruby 2.0. 在弹性beanstalk上,我正在使用它的默认负载均衡器,并且正在使用ruby 2.0运行ubuntu 64bit。

I'm getting two major problems: 我遇到两个主要问题:

1) the root route isn't working. 1)根路由不起作用。

  • In my config/routes.rb, I tried: 在我的config / routes.rb中,我试过:

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

    and found none of them working. 并发现他们都没有工作。 The server was giving me an error saying that: 服务器给我一个错误说:

    Invalid route name, already in use: 'root' (ArgumentError) 无效的路由名称,已在使用中:'root'(ArgumentError)

  • I guessed that there was some kind of clash between Rail's default root=>public/index.html and my own routing in config/routes.rb? 我猜想Rail的默认root => public / index.html和我自己在config / routes.rb中的路由之间存在某种冲突? So I created public/index.html and the root url '/' now serves public/index.html. 所以我创建了public / index.html,根url'/'现在提供public / index.html。 I want to figure out a way to make it work the 'Rails' way, with the root url routing to controller#action. 我想弄清楚一种方法,使它以“Rails”的方式工作,根网址路由到控制器#action。

2) Static assets are not being served. 2)没有提供静态资产。

Does anyone know the solutions for these problems? 有谁知道这些问题的解决方案?

Thank You in advance! 先感谢您!

========================= Edit =========================== =========================编辑======================== ===

I'm using Amazon 64bit Linux with Passenger Standalone 我正在使用带有Passenger Standalone的Amazon 64bit Linux

Try the following: 请尝试以下方法:

config/routes.rb 配置/ routes.rb中

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

Remove or comment out all definitions of '/' (including get '/', match '/', etc.) 删除或注释掉所有“/”的定义(包括获取'/',匹配'/'等)

app/controllers/home_controller.rb 应用程序/控制器/ home_controller.rb

class HomeController < ApplicationController

  def index
    render 'index'
  end

end

app/views/home/index.html.erb 应用程序/视图/家/ index.html.erb

<h1>HELLO WORLD.</h1>

And make sure to delete public/index.html . 并确保删除public / index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM