Skip to content

Commit

Permalink
Merge pull request #22 from Ch4s3/api_fix
Browse files Browse the repository at this point in the history
api fix
  • Loading branch information
Ch4s3 committed Nov 16, 2014
2 parents d77214f + 1daaec8 commit 0b05446
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ rerun.txt
pickle-email-*.html
.zeus.sock
.env
ngrok

# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
Expand Down
9 changes: 5 additions & 4 deletions app/controllers/api/spots_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def create
end

def index
@spots = LockUp.all
render json: @spots.to_json
spots = LockUp.all
spots_with_urls = spots.map{|s| s.to_json_with_photo_url}
render json: spots_with_urls
end

def find
Expand All @@ -22,8 +23,8 @@ def find
rad = params["lock_up"]["rad"].to_f || 0.1

results = LockUp.near([lat, lon], rad)
@json = results.map{|s| s.to_json_with_photo_url}
render json: @json
spots_with_urls = results.map{|s| s.to_json_with_photo_url}
render json: spots_with_urls
end

def vote
Expand Down
6 changes: 3 additions & 3 deletions app/models/lock_up.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class LockUp < ActiveRecord::Base
reverse_geocoded_by :lat, :lon
after_validation :reverse_geocode
has_attached_file :photo,
:styles => { :medium => "400x400>", :thumb => "100x100>" },
:styles => { :medium => "400x400>", :thumb => "150x150>" },
:default_url => "/images/:style/missing.png"
validates_attachment_content_type :photo, :content_type => /\Aimage\/.*\Z/

def to_json_with_photo_url
spot_json = JSON.parse(self.to_json)
spot_json['url'] = self.photo.url || ''
return spot_json.to_json
spot_json['url'] = self.photo.url(:medium) || ''
return spot_json
end
end

0 comments on commit 0b05446

Please sign in to comment.