How to check if local residents are identified in partial?

What is the correct syntax for checking if locales have been defined and passed in partial?

For example, I do partial

<%= render partial: "data-map", locals: {lat: @model.lat, lon: @model.lon, zoom: 10} %> 

And in a 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 have problems with this.

I also saw the following in the API

 <% if local_assigns.has_key? :headline %> Headline: <%= headline %> <% end %> 

but I also have problems with this. Maybe I am not getting the syntax correctly.

Thanks for any pointers

+4
source share
1 answer

Drop the if from the three-dimensional format as follows:

 <%= map( options: { latitude: defined?(lat) ? lat : 0, longitude: defined?(lon) ? lon : 0, zoom: defined?(zoom) ? zoom : 50 } %> 
+1
source

Source: https://habr.com/ru/post/1415781/


All Articles