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 || [])

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s