More Related Content Similar to Rails dev experices (20) Rails dev experices2. • 2013.4 - 2013.10 主⼒力开发nanfang.com
• 2013.10 - 2014.6 主⼒力开发ezitask项⽬目
⼯工作经历
• github https://github.com/lexuszhi1990
• blog http://lingzhi.me/
3. Ruby 语⾔言
❖ DRY / COC
❖ 简洁 稳定 拓展
❖ 语⾔言⼗〸十分接近⼈人类语⾔言
“?, !” 的应⽤用(“ Model.any?” “String.merge!”)
4. !, ? , <
❖ merge!
❖ any?
❖ class A < B
5. blocks, Procs, lambdas 和 Methods
❖ array.collect! { |n| n ** 2 }
❖ square = proc { |n| n ** 2 }
❖ lambda { |n| n ** 2 }
❖ def square(n); n ** 2 ; end
method(:square).call(9)
7. Ruby 编写规范
❖ guide style : https://github.com/bbatsov/
ruby-style-guide
❖ http://rocodev.gitbooks.io/rails-102/
content/chapter4-ruby/README.html
8. Rack
❖ a modular Ruby
webserver interface
❖ https://github.com/
rack/rack
❖ http://confreaks.tv/
videos/railsconf2013-
from-rails-to-the-web-
server-to-the-browser
10. Rails controller
❖ request 处理
❖ Sessions处理
❖ Cookies处理
❖ Flash消息处理
❖ Render結果
controller 需要做的事情
[ihower actioncontroller](https://ihower.tw/rails4/actioncontroller.html)
[action controller overview](http://guides.rubyonrails.org/action_controller_overview.html)
11. rails controller
❖ action_name
❖ cookies
❖ headers
❖ params
❖ request
❖ xml_http_request? 或 xhr?
❖ host_with_port
❖ remote_ip
❖ headers
❖ response
❖ session
Request中包含有的信息
http://api.rubyonrails.org/classes/ActionDispatch/Request.html
12. Skinny Controller
❖ controller 的代码最多10⾏行
❖ 使⽤用 Concern。 其实也就是我们通常说的 Shared Mixin Module。就
是把 Controllers/Models ⾥里⾯面⼀一些通⽤用的应⽤用逻辑抽象到⼀一个
Module ⾥里⾯面做封装,我们约定叫它 Concern
❖ Delegation Pattern
[ruby forwardable](http://ruby-doc.org/stdlib-2.0.0/libdoc/
forwardable/rdoc/Forwardable.html)
[dive into forwardable](http://www.saturnflyer.com/blog/jim/
2015/01/20/ruby-forwardable-deep-dive/)
❖ Service and Presenter
http://yedingding.com/2013/03/04/steps-to-refactor-
controller-and-models-in-rails-projects.html
13. rails model
❖ the layer of the system responsible for
representing business data and logic
❖ Object Relational Mapping
❖ http://guides.rubyonrails.org/
active_record_basics.html
15. PG - Extensions
❖ JSON
❖ Range Types
❖ Composite Types
❖ UUID
❖ Full Text Search
❖ fuzzystrmatch || Trigram
❖ cube
18. debugger
❖ pry
❖ log file
❖ https://speakerdeck.com/lidaobing/chu-liao-wen-ti-
bu-yao-kao-cai
❖ http://railscasts-china.com/episodes/do-not-guess-
the-problem-lidaobing