Rails 请求处理全解析
1. 路由断言
在进行路由测试时,有几个重要的断言方法。 assert_routing 方法可用于验证路由的正确性。以下是具体的使用示例:
def test_routing
assert_routing("/", :controller => "store", :action => "index")
assert_routing("/products", :controller => "products", :action => "index")
assert_routing({:path => "/line_items", :method => :post},
{ :controller => "line_items", :action => "create",
:product_id => "1"},
{}, { :product_id => "1"})
end
在使用时,需要注意在 options 哈希中使用符号作为键,字符串作为值,否则与路由返回的选项进行比较的断言可能会失败。
2. 请求处理流程
当控制器对象处理请求时,会按照以下流程进行:
1. 查找与传入动作同名的公共实例方法。若找到,则调用该方法。
2. 若未找到该方法,但控制器实现了 method_m
超级会员免费看
订阅专栏 解锁全文
29

被折叠的 条评论
为什么被折叠?



