Skip to content

Instantly share code, notes, and snippets.

View anathematic's full-sized avatar

Thomas anathematic

View GitHub Profile
UserGuest.blueprint do
username
password "12345"
password_confirmation "12345"
role
email
comments
end
... and then in my blueprint.rb
@contracts = Contract.find(:all,:joins =>'inner join sites on sites.id = contracts.site_id inner join cities on cities.id = sites.city_id inner join states st on st.id = cities.state_id inner join countries c on c.id = st.country_id', :conditions => ['deleted = 0 and sites.site_status_id <>3 and (contracts.end_date - current_date)< 240 and (contracts.end_date - current_date) > 0 and contracts.end_date is not null and c.id in (%s)', current_user.contact.country_ids_by_rights("sites","edit").join(",")], :order=>'contracts.end_date asc')
/* Global Reset */
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td { margin: 0; padding: 0; border: 0; outline: 0; font-size: 100%; vertical-align: baseline; background: transparent; }
ol, ul { list-style: none; }
blockquote, q { quotes: none; }
blockquote:before, blockquote:after, q:before, q:after { content: ''; content: none; }
:focus { outline: 0; }
table { border-spacing: 0; }
acronym { cursor: help; }
class ContractController < ApplicationController
def save
sc = params[:id].nil? ? Contract.new : Contract.find(params[:id])
sc.site_id = session[:site_id]
sc.site_contract_type_id = params[:contract][:site_contract_type_id].to_i
if Date.parse(params[:contract_info][:date_start]) > Date.parse(params[:contract_info][:date_end])
render :update do | page |
page.alert('Start Date can\'t be later than End Date.')
end
return
ContractIsp has many ContractIspPayables
it "should automatically create a contract_payable based on the payable out information provided (with three created if share is selected)" do
## Not sure how to approach building this in the model...
@contract_isp.update_attribute(:payable_by, "me")
@contract_isp.contract_isp_payables.size.should eql(1)
@contract_isp.update_attribute(:payable_by, "you")
@contract_isp.contract_isp_payables.size.should eql(3)
def build_payable_by_attributes
# Automatically build payable_by - in javascript we'll give the user control to change these on ContractIspsController#new
payable_by.eql?("shared") ? count = 3 : count = 1
remove_older_payment_amounts
count.times do
payable_amounts.build(:amount => 0) if payable_amounts.size != count
end
end
## Test
require 'active_merchant'
class Foo
include ActiveMerchant::Billing::CreditCardMethods
end
describe Foo do
it "should respond to methods in CreditCardMethods" do
@foo = Foo.new
Suggested way to present queries on resources based on longitude / latitude?
/api/stores/long/50/lat/50
/api/stores?long=50,lat=50
/api/stores/by-geo/50/50 (long should always be first by convention anyway?)
# Underscore returns the last value
ruby-1.9.2-p180 :002 > String.new("blah")
=> "blah"
ruby-1.9.2-p180 :003 > "blah" == _
=> true
## Postgres cares about your data
postgres_cares=# create table cakes (
postgres_cares(# name varchar(10)
postgres_cares(# );
CREATE TABLE
postgres_cares=# insert into cakes (name) values('super chocolate');
ERROR: value too long for type character varying(10)