首页 > 代码库 > rails再体验

rails再体验

掌握redmine plugin开发的目标在2016年未实现,2017年继续。

选择《Ruby on Rails Tutorial》教程,windows安装railsinstaller,该版本ruby为V2.1.8,和bitnami redmine-3.3.0版本一致。但rails版本为4.2.5.1,和redmine对应的4.2.6不一致。首先进行一次gem包更新:

  1. 启动终端。注意使用Railsinstall安装后自带的终端,终端里会设置环境。
  2. 修改gem源: bundle config ‘mirror.http://mirrors.aliyun.com/rubygems/‘ ‘http://gems.ruby-china.org/‘  # 2017.1.7 发现gems.ruby-china.org好用。
  3. gem install rails –version=4.2.6 –no-ri –no-rdoc

根据书中1.2.3章节在命令终端生成第一个程序:  rails new first_app, 出现以下错误:

run  bundle install
Fetching source index from http://mirrors.aliyun.com/rubygems/
Net::HTTPNotFound

进入第一个程序的根目录: cd first_app

重新运行bundle install,错误提示https://rubygems.org连接时认证错误,网上查询需要生成SSL认证,比较麻烦。直接修改first_app下的Gemfile:

source ‘https://rubygems.org‘

修改为:

source ‘http://gems.ruby-china.org/‘

再次运行bundle install,显示以下错误:

Using activesupport 4.2.6

Bundler::GemspecError: Could not read gem at D:/App/Coder/RailsInstaller/Ruby2.1
.0/lib/ruby/gems/2.1.0/cache/tzinfo-data-1.2016.10.gem. It may be corrupted.
Installing loofah 2.0.3
Installing mail 2.6.4
Using rails-deprecated_sanitizer 1.0.3
Installing globalid 0.3.7
Using activemodel 4.2.6
Installing jbuilder 2.6.1
An error occurred while installing tzinfo-data (1.2016.10), and Bundler cannot
continue.
Make sure that `gem install tzinfo-data -v ‘1.2016.10‘` succeeds before
bundling.

按照提示安装gem:

E:\05 Create\Code\temp\railstutorial\first_app>gem install tzinfo-data -v ‘1.201
6.10‘ --no-ri --no-rdoc
ERROR:  Error installing tzinfo-data:
        invalid gem: package is corrupt, exception while verifying: undefined me
thod `size‘ for nil:NilClass (NoMethodError) in D:/App/Coder/RailsInstaller/Ruby
2.1.0/lib/ruby/gems/2.1.0/cache/tzinfo-data-1.2016.10.gem

看起来目前版本不支持1.2016.10版本,换个低点的版本:

E:\05 Create\Code\temp\railstutorial\first_app>gem install tzinfo-data -v ‘1.201
5.6‘ --no-ri --no-rdoc
Fetching: tzinfo-data-1.2015.6.gem (100%)
Successfully installed tzinfo-data-1.2015.6
1 gem installed

同时修改Gemfile中的版本:

gem ‘tzinfo-data‘,platforms: [:mingw, :mswin, :x64_mingw, :jruby]

修改为:

gem ‘tzinfo-data‘, ‘1.2015.6‘ ,platforms: [:mingw, :mswin, :x64_mingw, :jruby]

再次bundle install运行成功,安装了56个gems。

因为版本已经和教程中的差异比较大(教程为ruby 2.0.0,rails 4.0.0),中间顺便对gem和bundle进行了升级:

gem update –system

bundle update # 因为上面升级了Rails gem版本,所以必须要执行

bundle install   # 再次安装所需的gem,其实已没有更新

启动rails server: rails server。 通过http://127.0.0.1:3000可查看第一个程序。

技术分享

rails再体验