Ruby On Rails : difference between render and `render partial: :template`| Passing locals in partials

render & render :partial

  • render is a shorthand for render :partial.
  • render will not accept additional local variables for the partial, you need to use render :partial as following for that:
    render partial: 'some/path/to/my/partial', locals: { custom_var: 'Hello' }

In Rails 4.2

#  code is in slim template
# Either this works 
= render 'tabbed_pact_view', pacts: (current_user.pacts || [])

# or

= render partial: 'tabbed_pact_view', locals: {pacts: (current_user.pacts || [])}

This wont work

= render partial: 'tabbed_pact_view', pacts: (current_user.pacts || [])