Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering partial with locals in Haml?

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.

like image 694
ssri Avatar asked Mar 10 '11 05:03

ssri


2 Answers

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 }
like image 56
Pravin Avatar answered Nov 04 '22 05:11

Pravin


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
like image 45
dearlbry Avatar answered Nov 04 '22 05:11

dearlbry