mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-09-25 15:34:55 -04:00
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Brenda Wallace <brenda@wallace.net.nz>
43 lines
1.0 KiB
Ruby
43 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class PlacesController < ApplicationController
|
|
skip_authorize_resource
|
|
respond_to :html, :json
|
|
|
|
MEMBER_FIELDS = %i[id login_name slug location latitude longitude].freeze
|
|
|
|
def index
|
|
respond_to do |format|
|
|
format.html
|
|
# json response is whatever we want to map here
|
|
format.json do
|
|
members = Member.located.paginate(page: params[:page]).pluck(*MEMBER_FIELDS).map do |row|
|
|
MEMBER_FIELDS.zip(row).to_h
|
|
end
|
|
render json: members
|
|
end
|
|
end
|
|
end
|
|
|
|
# GET /places/london
|
|
# GET /places/london.json
|
|
def show
|
|
@place = params[:place] # used for page title
|
|
@nearby_members = Member.nearest_to(params[:place])
|
|
respond_to do |format|
|
|
format.html # show.html.haml
|
|
format.json do
|
|
render json: @nearby_members.as_json(only: MEMBER_FIELDS)
|
|
end
|
|
end
|
|
end
|
|
|
|
def search
|
|
if params[:new_place].empty?
|
|
redirect_to places_path, alert: t('messages.invalid_location')
|
|
else
|
|
redirect_to place_path(params[:new_place])
|
|
end
|
|
end
|
|
end
|