Ruby-on-rails 在 Haml 中与当地人一起渲染部分内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5255874/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rendering partial with locals in Haml?
提问by ssri
I am learning Haml.
我正在学习哈姆勒。
My view files are like:
我的视图文件是这样的:
show.html.haml:
show.html.haml:
.content
= render 'meeting_info', :locals => { :info => @info }
and _meeting_info.html.haml:
和 _meeting_info.html.haml:
.detail
%table
%caption
Meeting Informations of
= info["meeting_name"]
...
When I tried running this I got an undefined local variable or method 'info'error.
当我尝试运行它时,undefined local variable or method 'info'出现错误。
回答by Pravin
Try this
Without :localsand :partial
试试这个
没有:locals和:partial
.content
= render 'meeting_info', :info => @info
No need to specify locals.
无需指定本地人。
With :localsand :partial
You should specify locals in following case i.e specifying :partialfor render
使用:locals和:partial
你应该在以下情况下指定本地人,即指定:partial渲染
.content
= render :partial => 'meeting_info', :locals => { :info => @info }
回答by dearlbry
You would use the :localsoption if you're calling render from a controller. When calling render from a view, you would simply do this:
:locals如果您从控制器调用渲染,您将使用该选项。从视图调用渲染时,您只需执行以下操作:
= render 'meeting_info', :info => @info

