Gmaps4rails 标记取决于当前用户

Gmaps4rails marker depending on current user

是否可以使用 gmaps4rails gem 查看标记,具体取决于当前用户登录?我不确定它是否有可能成功,但我尝试结合使用 cancan gem 但它只会导致所有标记消失。不幸的是,我不知道如何继续。所以我想要实现的是根据当前登录的用户使标记可见。非常感谢您的帮助!

relations_controller的当前代码:

    def index

    @relations = Relation.all

@hash1 = Gmaps4rails.build_markers(@relations) do |relation, marker|
    # something like "if current_user == relation.user_id" ?
    marker.lat relation.childlat
    marker.lng relation.childlng

    marker.picture({
              :url    => ActionController::Base.helpers.image_path("childgross.png"),
              :width  => "45",
              :height => "45"
             })
 end

@hash2 = Gmaps4rails.build_markers(@relations) do |relation, marker|
    marker.lat relation.kigalat
    marker.lng relation.kigalng
    marker.picture({
            :url    => ActionController::Base.helpers.image_path("persongross.png"),
            :width  => "45",
            :height => "45"
            })
 end
end

关系索引视图中的代码:

    <%=raw @hash1.to_json %>
    <%=raw @hash2.to_json %>

<script>
handler = Gmaps.build('Google');
handler.buildMap({provider: {},internal: {id: 'map'}},function(){
markers = handler.addMarkers(<%=raw @hash1.to_json %>);
markers = handler.addMarkers(<%=raw @hash2.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
</script>

感谢@Pablo 我刚想到...我只需要将 @relations = Relation.all 替换为 @relations = Relation.where(user_id: current_user.id)