【发布时间】:2013-08-04 20:28:08
【问题描述】:
我正在努力解决三个主要问题,感谢任何人的帮助。
1) 如何将 Rails 应用程序配置为以 myurl.com/myapp/ 作为根?
我在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 把它们放在那里/找到它们?
【问题讨论】:
标签: ruby-on-rails apache deployment ruby-on-rails-4 subdirectory