hamster 启动之layout
1、hamster 启动过程")首先是找到public\index.html ("method="post"action="/permission/login") 登录的request 被router 解析以后,找到相关的consroller,rails 会缺省在
app/views/layouts 目录下面找constroller_name.rhtm(.rxml)的文件(实际上是个layouts template)
if 存在 controller 对应的layouts 它将和action 对应的template 组合输出,如查没有ation 对应的template,layout也不会单独输出(如:采用render_text 输出就不会与layout结合)。有个特殊的layout--applicaton (所有controller的layout)
exp:
class PermissionController <>
layout 'framework',:except=>[:login]
#表示除login action 外都使用 framework.rhtml 做为layout.实际上在
view\permission\login.rhtml的存在。(与public\index.html类似),action logout
所现示的效查为 framework+logout.rhtml 的效果总给。
def login
case @request.method
when :post
if @session[:account] = Account.authenticate(@params[:account_login], @params[:account_password])
flash['notice'] = "登录成功"
redirect_to '/welcome'
下面是login.rhtml对 flash['notice']的引用。
<%= @flash['notice'] %>
,实际上login.rhtml的值还是融合在layout-applicaton 里。(也就是默认的)
<%= @content_for_layout %>
instance variable:@content_for_layout,它是一个String object,包含的是controller所递交的内容,controller在request被解析以后,进行rendering(递交),递交的内容来源于 template,也有可能来源于action本身,但总的说来,controller进行的递交操作会把数据传递到 @content_for_layout,这个instance variable里面,并且以String object形式存在,实际上它就是具体的html代码(template中的html),或者经过render(action中render_text 方法的返回值)的任何字符串。



0 Comments:
发表评论
<< Home