rails再体验(第一个程序)
2017-01-07 22:12
429 查看
掌握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包更新:
启动终端。注意使用Railsinstall安装后自带的终端,终端里会设置环境。
修改gem源: bundle config 'mirror.http://mirrors.aliyun.com/rubygems/' 'http://gems.ruby-china.org/' # 2017.1.7 发现gems.ruby-china.org好用。
gem install rails –version=4.2.6 –no-ri –no-rdoc
根据书中1.2.3章节在命令终端生成第一个程序: rails new first_app, 出现以下错误:
进入第一个程序的根目录: cd first_app
重新运行bundle install,错误提示https://rubygems.org连接时认证错误,网上查询需要生成SSL认证,比较麻烦。直接修改first_app下的Gemfile:
source 'https://rubygems.org'
修改为:
source 'http://gems.ruby-china.org/'
更彻底解决的方法是让rails生成的Gemfile文件里就修改source,在RailsInstaller\Ruby2.1.0\lib\ruby\gems\2.1.0\gems\railties-4.2.6\lib\rails\generators\rails\app\templates目录下修改Gemfile文件(同时修改source源和 tzinfo-data版本),这样rails new创建的Gemfile就ok了。
再次运行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可查看第一个程序。
20170108继续。 经过上述折腾后,根据教程2.2内容, 增加User资源:rails generate scaffold User name:string email:string出错,而且没有任何提示。最后的解决方法是使用rails new app重新生成应用,再运行上述指令就好了,猜测和rails new app后修改了Gemfile里gem版本有关系。
注意rails generate生成的app\models\user.rb内容如下:
class User < ActiveRecord::Base
看起来没有模型没有任何属性,一开始以为又是rails出了问题。根据网上内容,发现就该如此(数据库会正常创建属性,但是模型类就不包含该属性。刷新了我对ORM的认识)。
完成数据库迁移(bundle exec rake db:migrate)后启动服务器(rails s),通过客户端访问创建的Users(http://127.0.0.1:3000/users)又出错了
Showing E:/05 Create/Code/temp/railstutorial/test_app/app/views/layouts/application.html.erb where line #6 raised:
Application Trace | Framework Trace | Full Trace
继续搜索,找到答案,该文提供了3种解决方案。我用了第一种(删除了app\assets\javascripts\application.js文件中最后一行"//= require_tree .")解决,第3种方式看起来是根本解决,但对我的电脑无效。修改后访问正常:
选择《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包更新:
启动终端。注意使用Railsinstall安装后自带的终端,终端里会设置环境。
修改gem源: bundle config 'mirror.http://mirrors.aliyun.com/rubygems/' 'http://gems.ruby-china.org/' # 2017.1.7 发现gems.ruby-china.org好用。
gem install rails –version=4.2.6 –no-ri –no-rdoc
根据书中1.2.3章节在命令终端生成第一个程序: rails new first_app, 出现以下错误:
进入第一个程序的根目录: cd first_app
重新运行bundle install,错误提示https://rubygems.org连接时认证错误,网上查询需要生成SSL认证,比较麻烦。直接修改first_app下的Gemfile:
source 'https://rubygems.org'
修改为:
source 'http://gems.ruby-china.org/'
更彻底解决的方法是让rails生成的Gemfile文件里就修改source,在RailsInstaller\Ruby2.1.0\lib\ruby\gems\2.1.0\gems\railties-4.2.6\lib\rails\generators\rails\app\templates目录下修改Gemfile文件(同时修改source源和 tzinfo-data版本),这样rails new创建的Gemfile就ok了。
再次运行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可查看第一个程序。
20170108继续。 经过上述折腾后,根据教程2.2内容, 增加User资源:rails generate scaffold User name:string email:string出错,而且没有任何提示。最后的解决方法是使用rails new app重新生成应用,再运行上述指令就好了,猜测和rails new app后修改了Gemfile里gem版本有关系。
注意rails generate生成的app\models\user.rb内容如下:
class User < ActiveRecord::Base
end
看起来没有模型没有任何属性,一开始以为又是rails出了问题。根据网上内容,发现就该如此(数据库会正常创建属性,但是模型类就不包含该属性。刷新了我对ORM的认识)。
完成数据库迁移(bundle exec rake db:migrate)后启动服务器(rails s),通过客户端访问创建的Users(http://127.0.0.1:3000/users)又出错了
Showing E:/05 Create/Code/temp/railstutorial/test_app/app/views/layouts/application.html.erb where line #6 raised:
TypeError: 对象不支持此属性或方法
Rails.root: E:/05 Create/Code/temp/railstutorial/test_app
Application Trace | Framework Trace | Full Trace
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__1028411780_48770724'
继续搜索,找到答案,该文提供了3种解决方案。我用了第一种(删除了app\assets\javascripts\application.js文件中最后一行"//= require_tree .")解决,第3种方式看起来是根本解决,但对我的电脑无效。修改后访问正常:
相关文章推荐
- 总结体验1:就比如上面自己写的单链表建立这样的程序,其实明明知道输出单链表不能从头结点开始输入,而是要在第一个节点开始
- linux Ruby on Rails安装运行第一个小程序的两 个问题
- (绝对原创)Step By Step 如何写出自己的第一个JSP+JavaBean+Tomcat的程序(本人亲身体验+实例教学)
- Hibernate 第一个体验程序
- [转]10分钟写出你的第一个包含CRUD的Rails程序
- ASP.NET MVC 小牛之旅2:体验第一个MVC程序
- [Ruby on Rails系列]3、初试Rails:使用Rails开发第一个Web程序
- Struts 2.0初体验--参照Tutorials来写第一个Struts 2.0程序
- 创建第一个 Rails 程序(使用mysql)
- C#锐利体验 第一讲 “Hello,World!”程序
- 到现在为止,成功调试完成我的第一个Java程序,意味着我也要进行Java这一行了,请看我的代码!
- 自己做的觉得好玩的第一个JAVA程序
- 我的第一个socket程序!
- Hibernate入门02 - 第一个Hibernate程序
- Spring研究 (1) 第一个Spring MVC程序
- 我的第一个socket程序!
- 我的第一个Swing程序
- 用Eclipse MyEclipse WebLogic8.1开发第一个Web程序
- 自己的第一个Javascript程序
- mono:第一个gtk#程序