个人初学rails安装的一点点记录,还希望rails高手能指点一二.
1、安装ruby
不用说 是下载安装包:http://rubyforge.org/frs/?group_id=167,注意版本---害人不浅,后面会说到,我下的是1.8.6-26
装完后,可以用ruby -v 测试是否安装成功,如图,要是出现了版本 就说明安装成功了
2、安装完后ruby,安装rails
在命令行下运行 gem install rails,会有四五个提示 一路Y,安装完后,依旧可以用rails -v, 来检测rails 是否安装成功
3、创建Web应用
还是命令行下输入 rails testweb,比如当前的路径是 C:\Documents and Settings\Administrator>rails testweb,便会在C:\Documents and Settings\Administrator下创建一个testweb文件夹。
PS:这里是可以加路径的 比如 rails C://test,具体可以看官方API:http://api.rubyonrails.org/
4、在当前目录(testweb)下,运行 ruby script\server 启动服务,关于webrick服务器更多的信息可以访问 http://www.webrick.org/
5、浏览器中输入http://localhost:3000/,如果看到以前页面,说明OK
6、写一个HelloWorld的Web程序,ruby script\generate controller HelloWorld命令
然后找到到hello_world_controller.rb
输入以下代码,保存
class HelloWorldController < ApplicationController
def index
render:text&#61;>"hello world"
end
end
我曾经用 render_text "Hello RoR World" 试了半天也不管用&#xff0c;搜了半天才发现是版本的问题&#xff0c;经验啊
在浏览器中打开http://localhost:3000/hello_world&#xff0c;就会看见结果
PS:初学的一点点记录&#xff0c;还希望rails高手能指点一二.
1、或许有的朋友跟我一样 看不到hello world&#xff0c;查看日志&#xff0c;出现如下错误
Status: 500 Internal Server Error
no such file to load -- sqlite3
这是由于没有装sqlite3数据库&#xff0c;http://files.cnblogs.com/geek007/sqlite3.rar 这里下载&#xff0c;
然后解压到ruby的bin目录&#xff1a;D:\ruby\bin&#xff0c;命令行执行&#xff1a;gem install "D:\ruby\bin\sqlite3-ruby-1.2.3-mswin32.gem"
2、推荐一个cmd工具PowerCmd&#xff0c;用来替换系统的cmd&#xff0c;你会感觉很方便的。