在DreamHost上部署Rails程序
子域名labs.nanshapo.com,用ssh登录到系统。
[rollo]$ pwd
/home/liubin/labs.nanshapo.com
[rollo]$ rails front
/usr/bin/rails:17:Warning: require_gem is obsolete. Use gem instead.
create
create app/controllers
create app/helpers
.....................
create log/server.log
create log/production.log
create log/development.log
create log/test.log
[rollo]$
[rollo]$ cp front/public/.htaccess ./
[rollo]$ vi .htaccess
对.htaccess只有两个小小的修正:
RewriteRule ^(.*)$ front/public/dispatch.fcgi [QSA,L]
即将cgi改为fcgi,同时加入路径front/public/等。
创建一个控制器和2个简单的action
[rollo]$ ruby script/generate controller Main index test
exists app/controllers/
exists app/helpers/
create app/views/main
exists test/functional/
create app/controllers/main_controller.rb
create test/functional/main_controller_test.rb
create app/helpers/main_helper.rb
create app/views/main/index.rhtml
create app/views/main/test.rhtml
[rollo]$
修改router
[rollo]$ vi config/routes.rb
在适当的地方加入(或者将那个注释掉的改一下)
map.connect '',:controller=>"main"
这时候看了一下http://labs.nanshapo.com/
显示如下
Main#index
Find me in app/views/main/index.rhtml
再看看test action
http://labs.nanshapo.com/Main/test
显示
Main#test
Find me in app/views/main/test.rhtml
修改一下程序
- class MainController < ApplicationController
- def index
- @cip = request.remote_ip
- end
- def test
- @refer = headers["Referer"]
- end
- end
- #index.rhtml
- hello <%=@cip%>
- <br>
- <%=url_for :action=>"test"%>
- <br>
- <%= link_to "Go to test", :action => "test" %>
不过link_to和url_for产生的url都是/front/public/main/test 。明天看看怎么改吧。