Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's :locals for in render in rails?

Here is the API definition for render:

render(options = {}, locals = {}, &block)

Returns the result of a render that’s dictated by the options hash. The primary options are:

    :partial - See ActionView::Partials.

    :file - Renders an explicit template file (this used to be the old default), add :locals to pass in those.

    :inline - Renders an inline template similar to how it’s done in the controller.

    :text - Renders the text passed in out.

There is no explanation about what's the purpose of locals here? What's locals for?

Thanks.

like image 528
user938363 Avatar asked Dec 28 '22 08:12

user938363


1 Answers

To pass local variables to the partial template, as opposed to controller instance variables.

See Section 3.4.4, Passing Local Variables in the Layouts and Rendering Guide.

like image 109
Dave Newton Avatar answered Jan 08 '23 05:01

Dave Newton