Rails partials & locals
local_assigns
<%= render partial: "company", locals: { company: @company, foobar: "/barr" }
a/v/companies/_company.html.erb
<div><%= company.name %></div> <%= link_to foobar, foobar if local_assigns[:foobar] %>
render "partial_name" #renders "_partial_name.html.erb" render "partial_name", var1: "foo", var2: "bar" # pass local variables to partial render "partial_name", local_assigns # pass all localy assign variables to partial (usefull to pass all variables of partial to next partial)
Strict locals
since Rails 7.1 you can do
a/v/companies/_company.html.erb
<%# locals: (company:) %> <div><%= company.name %>
Defaults
<%# locals: comany, active: params[:active]) -%>
<%# locals: (paypal: PaymentGateway.find_by_name("paypal"), braintree:...) -%>
sources: