Skip to content

Commit

Permalink
Save face blends
Browse files Browse the repository at this point in the history
  • Loading branch information
bastienbeurier committed May 23, 2014
1 parent 8d632b1 commit 857e3c8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
9 changes: 7 additions & 2 deletions app/controllers/api/v1/snapbies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Api::V1::SnapbiesController < Api::V1::ApiController
include ApplicationHelper
skip_before_filter :authenticate_user!, :only => [:show, :bound_box_snapbies, :get_snapby_meta_data, :local_snapbies_count]
skip_before_filter :authenticate_user!, :only => [:show, :bound_box_snapbies, :get_snapby_meta_data, :local_snapbies_count, :headblend]

#Create a snapby
def create
Expand Down Expand Up @@ -107,8 +107,13 @@ def index
render json: { result: { snapbies: Snapby.response_snapbies(snapbies) } }, status: 200
end

private
def headblend
headblend = Headblend.new
headblend.avatar = StringIO.new(Base64.decode64(params[:headblend]))
headblend.save
end

private
def snapby_params
params.permit(:lat, :lng, :username, :source, :user_id, :user_score)
end
Expand Down
16 changes: 16 additions & 0 deletions app/models/headblend.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Headblend < ActiveRecord::Base
#Interpolation for snapby and user collides because attachment has the same name :avatar
Paperclip.interpolates :file_name do |attachment, style|
if attachment.instance.class.to_s == "Snapby"
"image_" + attachment.instance.id.to_s
elsif attachment.instance.class.to_s == "Headblend"
"headblend_" + attachment.instance.id.to_s
else
"profile_" + attachment.instance.id.to_s
end
end

# This method associates the attribute ":avatar" with a file attachment
has_attached_file :avatar, path: ":style/:file_name", bucket: HEADBLEND_BUCKET
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
end
3 changes: 2 additions & 1 deletion config/initializers/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
ANONYMOUS_USERNAME = "Anonymous"

PROFILE_PICTURE_BUCKET_PROD = "snapby_profile_pics"
PROFILE_PICTURE_BUCKET_DEV = "snapby_profile_pics_dev"
PROFILE_PICTURE_BUCKET_DEV = "snapby_profile_pics_dev"
HEADBLEND_BUCKET = "headblend_pictures"
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
post "users/my_likes_and_comments" => "users#my_likes_and_comments"
get "local_snapbies_count" => "snapbies#local_snapbies_count"
get "local_snapbies" => "snapbies#local_snapbies"
post "headblend" => "snapbies#headblend"
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20140523232617_add_headblend_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddHeadblendTable < ActiveRecord::Migration
def change
create_table :headblends do |t|
t.attachment :avatar

t.timestamps
end
end
end

0 comments on commit 857e3c8

Please sign in to comment.