打印

render的疑问

render的疑问

def index
 list 
  render(:action => 'list')
 end
==
这个list放在这里有什么作用?放与不放有什么不同?

TOP

render是渲染页面的意思
这里你在index方法里,如果不render(:action => :list)
会自动去找index.rhtml
如果你没有index.rhtml就会现error

但你render 到了list就会去找list.rhtml了

注意:action => :list这里最好这么写
like predefine variable
http://www.smellcode.cn
There's more than one way to do it.
http://www.rubyway.cn

TOP

我明白render的意思。但我说的是.
def index
 list 
  render(:action => 'list')
 end
与def index
 list 
  render(:action => 'list')
 end
=
的分别

TOP

没看出来有什么不同?
谢谢大家加入Ruby中文社区!
[寻找您身边的Rubyist.]

TOP

我想你表达出了些问题
like predefine variable
http://www.smellcode.cn
There's more than one way to do it.
http://www.rubyway.cn

TOP

我明白render的意思。但我说的是.
def index
 list 
  render(:action => 'list')
 end
与def index
  render(:action => 'list')
 end
=
的分别

TOP

写漏了,第二个没有list的。
当我不写上list的时候,有时候会出错的。提示有对象不能为空

TOP

哦,我明白楼主的意思了。

可能是这样的。在before_filter里面指定了nly => :list,这样当在index里调用 list 的时候,这个filter并不会被触发,因此就发生了空引用的错误。
谢谢大家加入Ruby中文社区!
[寻找您身边的Rubyist.]

TOP

引用:
原帖由 livahu 于 2007-7-24 10:40 发表
render是渲染页面的意思
这里你在index方法里,如果不render(:action => :list)
会自动去找index.rhtml
如果你没有index.rhtml就会现error

但你render 到了list就会去找list.rhtml了

注意:action => : ...
这个"list"和:list好象关系也没这么大吧,我是想到怎么写了就怎么去写哈。

TOP

用symbol能提高性能
要注意有时候去考虑性能
like predefine variable
http://www.smellcode.cn
There's more than one way to do it.
http://www.rubyway.cn

TOP

scaffold自动生成的。

TOP

引用:
原帖由 cclong 于 2007-7-24 18:00 发表
我明白render的意思。但我说的是.
def index
 list 
  render(:action => 'list')
 end
与def index
 list 
  render(:action => 'list')
 end
=
的分别
好象是一樣的啊!

TOP

我在猜想,會先調用過一次list,然後再給render做處理吧
但是事實上有沒有或許是沒有太大的差別

有些地方可不能用symbol.. 否則會出錯

TOP

2008-11-22 20:17 Crawled by CCBot/1.0 (+http://www.commoncrawl.org/bot.html) @38.103.63.61