This file contains 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
module UserHelpers | |
def current_user_session | |
return @current_user_session if defined?(@current_user_session) | |
@current_user_session = UserSession.find | |
end | |
def current_user | |
return @current_user if defined?(@current_user) | |
@current_user = current_user_session && current_user_session.user | |
end |
This file contains 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
class Api::ItemsController < ApplicationController | |
respond_to :json | |
def create | |
begin | |
puts "params: #{params}" | |
post_data = params[:item_post].is_a?(String) ? JSON.parse(params[:item_post]) : params[:item_post] | |
user_data = post_data['user'] || {} | |
item_data = post_data['item'] || {} |
This file contains 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
class ItemImage < ActiveRecord::Base | |
belongs_to :item | |
mount_uploader :image, ImageUploader | |
before_save :extract_geolocation | |
def extract_geolocation | |
img = Magick::Image.read(image)[0] rescue nil | |
This file contains 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
extension String { | |
var camelCased: String { | |
let items = self.components(separatedBy: "_") | |
return items[1...].reduce(items[0].lowercased(), { $0 + $1.capitalized }) | |
} | |
} |