Rendering partial with locals in Haml?

喜夏-厌秋 提交于 2019-11-27 10:48:00

问题


I am learning Haml.

My view files are like:

show.html.haml:

.content
  = render 'meeting_info', :locals => { :info => @info }

and _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.


回答1:


Try this
Without :locals and :partial

.content
  = render 'meeting_info', :info => @info

No need to specify locals.

With :locals and :partial
You should specify locals in following case i.e specifying :partial for render

.content
  = render :partial => 'meeting_info', :locals => { :info => @info }



回答2:


You would use the :locals option if you're calling render from a controller. When calling render from a view, you would simply do this:

= render 'meeting_info', :info => @info


来源:https://stackoverflow.com/questions/5255874/rendering-partial-with-locals-in-haml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!