Rails在Windows下的环境搭建,包含一些常见问题的解决
http://rubyinstaller.org/downloads/
因为在国内https://rubygems.org经常被墙,所以修改为淘宝的gem源http://ruby.taobao.org
> gem source -l > gem sources --remove https://rubygems.org/ > gem sources -a http://ruby.taobao.org/ > gem sources -lDevKit-tdm-32-4.5.2-20111229-1559-sfx.exe
设置bin目录到Path变量
打开RubyMine,新建一个项目,项目类型选择Rails Application,选择OK,下一步,选择RailsVersion下拉框,IDE会自动下载Rails以及相关的依赖,数据库选择mysql,确定即可.也可以通过命令行下载.
点击运行启动WEBrick(内置的HTTP服务器),启动成功后,会在命令行提示
[2013-05-25 01:03:05] INFO WEBrick 1.3.1 [2013-05-25 01:03:05] INFO ruby 2.0.0 (2013-02-24) [i386-mingw32] [2013-05-25 01:03:05] INFO WEBrick::HTTPServer#start: pid=41664 port=3000打开浏览器输入localhost:3000,如果可以看到Rails的默认页面,那么恭喜你成功了少年,你穿越了千难万险,终于见到了拉比克大魔王.当然不是所有的人都这么幸运,安装过程中会遇到各种各样的问题
The XXX native gem requires installed build tools,Please update your PATH to include build tools or download the DevKit from 'http://rubyinstaller.org/downloads' and follow the instructions at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
这个问题主要出现在安装Rails的时候,主要是Devkit没有装好,请参考前面说明安装cannot load such file -- mysql2/2.0/mysql2
找不到mysql2,请确保mysql是否安装复制Mysql安装目录下lib文件夹中的libmysql.dll复制到Ruby安装目录的bin目录下发现Ruby200\lib\ruby\gems\2.0.0\gems\mysql2-0.3.11-x86-mingw32\lib\mysql2中没有2.0文件夹,只有1.8,1.9,重新通过gem安装mysql2,我用的mariadb-10.0.2
gem install mysql2 -- '--with-mysql-dir="MySql安装目录"' //如果出现下面类似的错误 checking for mysql.h... no //检查MySql\include\中有没有这个文件,如果在\include\Mysql中,复制出来安装成功后发现在Ruby200\lib\ruby\gems\2.0.0\gems多了一个目录mysql2-0.3.11,这其中就是我们要的东西,把mysql2-0.3.11\lib\mysql2中的mysql2.so复制出来,在mysql2-0.3.11-x86-mingw32\lib\mysql2中新建一个2.0文件夹,复制进去
RubyMine Gem Manager RubyMine has detected that some of the gems required for 'railsHelloWorld' are not installed Install missing gems
RubyMine会自动检测是否有依赖未安装,点击提示就可以安装了,主要是别忘了要把Gemfile第一行源改成http://ruby.taobao.orgAccess denied for user 'root'@'localhost' (using password: NO) (Mysql2::Error)
在config/database.yml修改数据库地址,用户名,密码,数据库名称确保Mysql已经启动,并且帐号密码正确,指定的数据库存在
转载于:https://www.cnblogs.com/Mercurius/archive/2013/05/25/3098291.html