I am using Gmaps4Rails to display a map that has markers. When each marker is clicked on, my intention is for the infowindow to show a table of information about that specific marker only. I am using a partial to generate this table, however whenever any pin is clicked, the table shows the data about every other pin as well. I believe I need an if statement in the partial that compares which pin is being clicked on in the controller to the data being generated by the partial. Unfortunatly, the if statement I currently have substitutes the correct company based on which pin is clicked, into the name slot for every row in the table but does not limit which rows are returned. How can I write an if statement in the partial that will return only the correct row?
controller.rb:
def index
@internships = Internship.all
@internship_properties = Array.new
@internships.each do |internship|
@internship_properties.push(internship)
end
@hash = Gmaps4rails.build_markers(@internship_properties) do |internship_prop, marker|
marker.lat internship_prop.latitude
marker.lng internship_prop.longitude
marker.infowindow render_to_string(:partial => "/internships/info", :locals => { :internship => @internship, :internship_prop => internship_prop.company})
end
end
_info.html.erb
<% @internships.each do |internship| %>
<% if internship.address = internship_prop %>
<h3><%=internship.address%></h3>
<h5>Name: <%=internship.name%></h5>
<table class="table table-hover">
<tr>
<th>Company</th>
<th>Title</th>
<th>Date</th>
<th>Description</th>
</tr>
<tr>
<td><%=internship.company%></td>
<td><%=internship.title%></td>
<td><%=internship.date%></td>
<td><%=internship.description%></td>
</tr>
</table>
<% end %>
<% end %>
You should have:
<% if internship.address == internship_prop %>
instead of
<% if internship.address = internship_prop %>
in _info.html.erb. Singular =
symbol stands for assignment which will return the assigned value and ==
stands for actual comparison.
But from what I understood from Your description, the controller should return only the data for selected pin. Maybe consider using ajax
call to get only the data for the selected pin asynchronously, instead of loading all the internships
. You can use for example jQuery load()
function.