我正在努力解决三个主要问题,我感谢对其中任何一个的帮助。
1) 如何将 Rails 应用程序配置myurl.com/myapp/
为 root?
我试过了routes.rb
:
scope '/myapp' || '/' do
# all resources and routes go here
root :to => "papers#index"
resources :papers
end
在environment.rb
,我把它加到了顶部
ENV['RAILS_RELATIVE_URL_ROOT'] = "/myapp"
这几乎可以工作,除了rake routes
不为“/”打印任何路线,并GET myurl.com/myapp/
产生ActionController::RoutingError (No route matches [GET] "/")
2)需要告诉apache什么?
我的共享服务器的提供者建议把它放到~/html/.htaccess
RewriteEngine on
RewriteRule ^myapp/(.*)$ /fcgi-bin/rails4/$1 [QSA,L]
与/fcgi-bin/rails4
存在
#!/bin/sh
# This is needed to find gems installed with --user-install
export HOME=/home/kadrian
# Include our profile to include the right RUBY
. $HOME/.bash_profile
# This makes Rails/Rack think we're running under FastCGI. WTF?!
# See ~/.gem/ruby/1.9.1/gems/rack-1.2.1/lib/rack/handler.rb
export PHP_FCGI_CHILDREN=1
# Get into the project directory and start the Rails server
cd $HOME/rails4
exec bundle exec rails server -e production
当我单击站点上的任何链接时,浏览器 url 会更改为myurl.com/fcgi-bin/rails4/papers/1
,例如它应该在的位置myurl.com/myapp/papers/1
。我怎样才能防止这种情况?
3)如何让资产运作
我觉得这将与1)和2)一起以某种方式解决。但是,现在,该应用程序尝试执行以下操作:
GET myurl.com/assets/application-5e86fb668d97d38d6994ac8e9c45d45e.css
这会产生一个404 Not Found
. 资产也应该在子目录下,对吧?我如何告诉 rails 把它们放在那里/找到它们?