每天一剂Rails良药知识库 |
||
|
未分类文章
Rails源码研究之ActionView:一,基本架构和ERB
先看源码再分析 1,action_view.rb $:.unshift(File.dirname(__FILE__) + "/action_view/vendor") require 'action_view/base' require 'action_view/partials' ActionView::Base.class_eval do include ActionVie ...
Rails源码研究之ActionController:十,pagination
1,action_controller\pagination.rb: module ActionController module Pagination def paginate(collection_id, options={}) Pagination.validate_options!(collection_id, options, true) paginator_and_collection ...
Rails源码研究之ActionController:九,mime_responds
Rails从HTTP Accept header得到客户端需要的response format信息 默认的MIME types见mime_type.rb: ALL = Type.new "*/*", :all TEXT = Type.new "text/plain", :text HTML = Type.new "text/html", ...
Rails源码研究之ActionController:八,resources
深入了解一下ActionController的Resources--RESTful Rails 1,ActionController的resources用来实现REST api,一个单独的resource基于HTTP verb(method)有不同的行为(action),如: map.resources :messages class MessagesController < Action ...
Rails源码研究之ActionController:七,filters
我们上次看过了ActiveRecord的callbacks,这次看看ActionController的filters 1,filter继承 先执行父类中的filter,再执行子类中的filter,如果父类中的filter返回false,则不执行子类中后续的filter 2,filter类型 1)method reference(symbol) class BankController < ...
Rails源码研究之ActionController:六,request
看看Rails的request/response源码吧,非常有趣,有些方法非常实用 1,request.rb: module ActionController class AbstractRequest def method @request_method ||= (!parameters[:_method].blank? && @env['REQUEST_METHOD'] == ...
Rails源码研究之ActionController:五,cookies
cookies.rb: module ActionController module Cookies protected def cookies CookieJar.new(self) end end class CookieJar < Hash def initialize(controller) @controller, @cookies = controller, controller ...
Rails源码研究之ActionController:四,session
我们知道Rails默认使用file来存储session数据,放在tmp\sessions目录下 其实我们还可以使用数据库、drb_server、mem_cache甚至内存来存储session数据 方法就是更改environment.rb: config.action_controller.session_store = :active_record_store || :drb_store || : ...
Rails源码研究之ActionController:三,scaffolding
Rails里富有Magic的东西往往实现起来非常简单,比如scaffolding 看看代码先,scaffolding.rb: module ActionController module Scaffolding def self.included(base) base.extend(ClassMethods) end module ClassMethods def scaffold(model_i ...
Rails源码研究之ActionController:二,routing
满城尽带黄金甲,源码尽在routing.rb: module ActionController module Routing class Route attr_accessor :segments, :requirements, :conditions end class RouteBuilder def build(path, options) path = "/#{path}&quo ...
Rails源码研究之ActionController:一,基本架构、render、redirect
1,action_controller.rb: $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) unless defined?(ActiveSupport) begin $:.u ...
Rails源码研究之ActiveRecord:六,Acts
ActiveRecord自带了三种数据结构关系:acts_as_tree、acts_as_list、acts_as_nested_set 1,tree.rb module ActiveRecord module Acts module Tree def self.included(base) base.extend(ClassMethods) end module ClassMethods de ...
Rails源码研究之ActiveRecord:五,Callbacks
Callbacks相关的源码在callbacks.rb文件里: module ActiveRecord module Callbacks CALLBACKS = %w( after_find after_initialize before_save after_save before_create after_create before_update after_update before_val ...
Rails源码研究之ActiveRecord:四,Validations
Validations相关的源码全在validations.rb文件里: module ActiveRecord class Errors include Enumerable @@default_error_messages = { :inclusion => "is not included in the list", :exclusion => "i ...
Rails源码研究之ActiveRecord:三,Transactions
这次我们分析一下Rails的事务支持 1,Rails默认将父子关系的表的save()和destroy()包装在一个事务里(见AWDWR一书的Transactions) 这保证了父子保存和删除的原子性,即ActiveRecord是级联保存和级联删除的,有源码为证 transactions.rb: module ActiveRecord module Transactions def self.inc ...
群组知识库热门文章
最新评论
不能适应超过三层的的override,比如我有A,B,C三个模板,B在A的基础上添加自己的东西,C在B ...
mingliangfeng 评论了 Rails宝典之第八式: layout与content_for
mingliangfeng 评论了 Rails宝典之第八式: layout与content_for
[/b][i][/i][u][/u]引用[color=red][/color][size=medium ...
linjie_830914 评论了 Rails源码研究之ActionController:二,ro ...
linjie_830914 评论了 Rails源码研究之ActionController:二,ro ...