Last active
December 14, 2015 13:18
-
-
Save davetapley/5092030 to your computer and use it in GitHub Desktop.
When hitting the `index` action at `/places.json` I'm always getting a `200` and the expected JSON. But hitting the `map` action at `/places/map.json` always gives `304`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/routes.rb | |
resources :places, only: [:index, :edit, :update], constraints: {format: :json} do | |
collection do | |
get 'map' | |
end | |
# app/controllers/places_controller.rb | |
def index | |
@all_places = current_user.places.with_location.certain_or_been_to | |
end | |
def map | |
@weeks_places = current_user.places.with_location.certain_or_been_to.visited_in week_range | |
end | |
# app/models/places.rb | |
scope :with_location, where('places.latitude != 0 AND places.longitude !=0') | |
scope :certain_or_been_to, where('places.certain = 1 OR place_events_count > 0') | |
scope :visited_in, lambda { |range| joins(:place_events).where(place_events: { start_time: range }).uniq } | |
# app/views/places/index.rabl | |
node do | |
{ name: current_user.first_name, | |
visited_number: @all_places.size, | |
visited_period: Time.now - current_user.created_at, | |
time_zone: Time.zone.to_s, time_zone_offset: Time.zone.formatted_offset } | |
end | |
child PlaceDecorator.decorate_collection(@all_places) => :places_table do |place| | |
attributes :id, :name, :confirmed | |
attributes :category_filename => :category, :visit_count => :visits, :last_visit_iso8601 => :last_time | |
end | |
# app/views/places/map.rabl | |
collection PlaceDecorator.decorate_collection(@weeks_places) => :places_map | |
attributes :id, :name, :confirmed | |
attributes :latitude => :lat, :longitude => :lng | |
attributes :category_filename => :category, :visit_count => :visits, :last_visit_iso8601 => :last_time | |
# app/decorators/place_decorator.rb | |
# has nothing weird in it, I assure you |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment