Commit 66ea71b

mo khan <mo@mokhan.ca>
2016-05-01 21:11:43
extract url method for location model.
1 parent d456b6c
Changed files (2)
app
app/models/location.rb
@@ -10,6 +10,10 @@ class Location < ActiveRecord::Base
     latitude == 0.0 && longitude == 0.0 ? [] : [latitude, longitude]
   end
 
+  def url
+    "https://maps.google.com/?q=#{latitude},#{longitude}"
+  end
+
   class << self
     def build_from_ip(ip)
       result = search(ip)
app/views/gyms/index.html.erb
@@ -10,7 +10,7 @@
         <tr>
         <td><%= gym.name %></td>
         <td><%= gym.location.address %>, <%= gym.location.city %>, <%= gym.location.region %>, <%= gym.location.country %></td>
-        <td><a href="https://maps.google.com/?q=<%= gym.location.latitude %>,<%= gym.location.longitude %>" target="_blank"><%= t('.view_map') %></a></td>
+        <td><%= link_to t('.view_map'), gym.location.url %></td>
       </tr>
     <% end %>
     </table>