有没有办法使用gmaps4rails gem查看标记,具体取决于当前用户登录?我不确定它是否有可能已经解决,但我尝试组合使用康康宝石,但它只会导致所有标记消失。不幸的是,我不知道如何继续。所以我想要实现的是根据当前登录的用户使标记可见。我很感激任何帮助!
relations_controller的当前代码:
$model = LoanInformation::select(
'loan_information.id', 'loan_information.tenor',
'basic_information.first_name', 'basic_information.last_name'
)->leftjoin(
'basic_information', 'loan_information.user_id', '=',
'basic_information.user_id'
)->where('loan_information.status', 'funding')
->orderBy('loan_information.created_at', 'ASC')
->paginate(9);
foreach($model as $key => $value) {
$tx_funding = TxFunding::whereLoanId($value->id)->get();
$name = substr($value->first_name, 0, 1).substr($value->last_name, 0, 2);
$model[$key]['name'] = strtoupper($name);
$model[$key]['grade'] = 'A+';
$model[$key]['fundraiser'] = $tx_funding->count();
$model[$key]['progress'] = 50;
$model[$key] = array_except($value, ['first_name', 'last_name']);
}
return response()->json($model);
关系索引视图中的代码:
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
答案 0 :(得分:0)
向@Pablo致敬它刚刚来找我......我只需要用@relations = Relation.all
替换@relations = Relation.where(user_id: current_user.id)