What is the correct syntax to test if locals have been defined and passed to a partial?
For example, I render a partial
<%= render partial: "data-map", locals: {lat: @model.lat, lon: @model.lon, zoom: 10} %>
And in the partial need to do something like
<%= map( options: {
latitude: if lat.defined? ? lat : 0,
longitude: if lon.defined? ? lon : 0,
zoom: if zoom.defined? ? zoom : 50
}
%>
I'm having trouble getting this working.
I also saw the following in the API
<% if local_assigns.has_key? :headline %>
Headline: <%= headline %>
<% end %>
but am having trouble with this as well. Perhaps I'm not getting the syntax correct.
Grateful for any pointers
Drop the if from the ternary format as follows:
<%= map( options: {
latitude: defined?(lat) ? lat : 0,
longitude: defined?(lon) ? lon : 0,
zoom: defined?(zoom) ? zoom : 50
}
%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With