require 'sinatra' require 'sinatra/activerecord' require 'json' require './environments' set :public_folder, 'public' get '/' do @raids = Raid.all erb :index end post '/' do response['Access-Control-Allow-Origin'] = 'http://trugul.com' @raid = Raid.new(params[:raid]) if @raid.save content_type :json { :message => 'Raid saved' }.to_json else content_type :json { :message => 'Raid failed to save' }.to_json end end class Raid < ActiveRecord::Base def money=(value) value = value.to_s.gsub(/[$,]/, '').to_f write_attribute(:money, value) end def soldiers=(value) value = value.to_s.gsub(/[$,]/, '').to_f write_attribute(:soldiers, value) end end