号称: 代替发挥component作用的controller, 这样就不需要邪恶的render_component了
A cell acts as a lightweight controller in the sense that it will assign variables and render a view.
cell可以用session, params, request等方法访问 父控制器的对应参量
但其它局部变量和实例变量 默认不会传到cell里面
The controller's instance variables and params hash are not directly available from the cell or its views.
目录结构:
- app/
- models/
- views/
- helpers/
- controllers/
- cells/
- my_cell.rb #cell 'controller'
- my_cell/ #cell 'views'
- show.html.erb
- ...
app/
models/
views/
helpers/
controllers/
cells/
my_cell.rb #cell 'controller'
my_cell/ #cell 'views'
show.html.erb
...
cell可以用application helper,若要使用其他helper需声明,如:
- class ShoppingCartCell < Cell::Base
- helper :product
- ....
- end
class ShoppingCartCell < Cell::Base
helper :product
....
end
使用:
- <%= render_cell :my_cell, :show %>
<%= render_cell :my_cell, :show %>
=======================邪恶的component回顾=========================
component 组装页面的使用方式大致如下:
- render_component :controller=>..., :action=>..., :params=>{...}
render_component :controller=>..., :action=>..., :params=>{...}
rails似乎没有提供以path/url作component的方式,所以只好用
- render_component ( ActionController::Routing::Routes.recognize_path("/some/action") ) #how ugly!
render_component ( ActionController::Routing::Routes.recognize_path("/some/action") ) #how ugly!
想要包含外部页面为组件,其中一个办法是用esi:include标签。。。
只有用render_component才能调用其他action及action之上的过滤器并包含其结果,而且很慢 ...
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




