ruby on rails 学习流水账

按照教程,把ror环境跑起来了,接起来两周会多花一些时间在学习上。

环境安装的流程还是需要备注一下

通读下文
http://huacnlee.com/blog/how-to-start-learning-ruby-on-rails/

安装过程参考
http://ruby-china.org/wiki/install_ruby_guide
http://about.ac/rails-tutorial-2nd-cn/chapter1.html
https://github.com/sstephenson/rbenv 目前用rbenv更顺手

安装时遇到一个js运行环境的问题,暂时没搞懂ror和js环境有啥子关系
http://ruby-china.org/topics/692

hello world
http://guides.ruby-china.org/getting_started.html

然后再给自己选了一个ide,ide对新手来说,还是很重要的,特别是代码提示
http://www.jetbrains.com/ruby/features/index.html

下载地址:
http://www.jetbrains.com/ruby/download/index.html
破解序列号:
name: rubymine
LICENSE:
70414-12042010
00002VG0BeoZbwmNAMNCx5E882rBEM
Ysn1P!e”s830EDlHcWg8gmqYVkvZMo
Injf4yqlO1yy”82NiwNzyYInoT7AiX

看了大家的测试安全部署平台,我也在appfog.com上注册了一个账号进行试用,简单来说,不会使用git的同学,压力会比较大了。
git除了在指定文件和目录方面的管理功能比较蛋疼以外,如更新和历史,其它地方都好过svn。现在用git的地方真是太多了,当然,学习的过程真是很混乱的。一开始使用git的时候,完全把git当成了svn用。

生成一个rails项目,后面的参数表示不安装bundle
rails new demo –skip-bundle –skip-test-unit -d mysql

修改gem源地址以提高bundel install速度
source ‘http://ruby.taobao.org/
bundle install

提高rails new时bundle install运行速度
rails new demo –skip-bundle
cd demo
bundle install –local –without production

使用mysql作为数据库,生成一个CURD的功能
http://rubyer.me/blog/231/

体验一次ThinkPHP里的数据库模型,简单看一下高级方法和数据验证方法

[ruby]
class Micropost < ActiveRecord::Base
attr_accessible :content, :user_id

#自定义数据校验
validates_presence_of :first_name, :last_name
validates :content, :length => { :minimum => 2, :maximum => 20 }

#数据校验器
validate :no_blank_content

=begin
:acceptance => Boolean
:confirmation => Boolean
:exclusion => { :in => Ennumerable }
:inclusion => { :in => Ennumerable }
:format => { :with => Regexp }
:length => { :minimum => Fixnum, maximum => Fixnum, }
:numericality => Boolean
:presence => Boolean
:uniqueness => Boolean
=end

belongs_to :user
end

def no_blank_content
if content.blank?
errors.add( :content, "can not be null")
end
if user_id.blank?
errors.add( :user_id, "can not be null")
end
end
[/ruby]

无比强大,又好玩的console
rails console

目前发现的问题
1,文件名都是小写的,加复数,类名变量名却是大写的,而且变量区分大小写
2,编程语法跟英语语法折腾到一堆了,比如默认加复数、很多关键词与c语言不一样,nil|empty,delete|destroy
3,ruby on rails,框架大集成,jQuery都是框架集成功能,对各种包,工具依赖强烈,入门学习成本高,感觉git不熟,命令不熟悉,mvc概念不熟悉的新手,学习起来超级困难

一本不错的入门书及视频
http://about.ac/rails-tutorial-2nd-cn/
ed2k://|file|%5BRuby.on.Rails.3.%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B%5D.RubyOnRails3LiveLessons.iso|7941357568|cd5c6b189bcf9c481206d5c62427c2d3|h=douoii3zqelwejjlrpi4iodtozbvadxa|/

发表评论