手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>程序设计>Java技术>列表

有人用过cell么?

来源: 作者: 时间:2008-04-02
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!
非常小,源代码一目了然。感觉虽然有点土,但比自己做个module的方式好一点点
号称: 代替发挥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.

目录结构:
Java代码 复制代码
  1. app/   
  2.      models/   
  3.      views/   
  4.      helpers/   
  5.      controllers/   
  6.      cells/   
  7.         my_cell.rb  #cell 'controller'  
  8.         my_cell/    #cell 'views'  
  9.             show.html.erb   
  10.             ...  
cell可以用application helper,若要使用其他helper需声明,如:
Ruby代码 复制代码
  1. class ShoppingCartCell < Cell::Base   
  2.      helper :product  
  3.      ....   
  4. end  
使用:
Ruby代码 复制代码
  1. <%= render_cell :my_cell:show %>  




=======================邪恶的component回顾=========================

component 组装页面的使用方式大致如下:
Ruby代码 复制代码
  1. render_component :controller=>..., :action=>..., :params=>{...}  

rails似乎没有提供以path/url作component的方式,所以只好用
Ruby代码 复制代码
  1. render_component ( ActionController::Routing::Routes.recognize_path("/some/action") ) #how ugly!  

想要包含外部页面为组件,其中一个办法是用esi:include标签。。。
只有用render_component才能调用其他action及action之上的过滤器并包含其结果,而且很慢 ...

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!