Skip to content

Instantly share code, notes, and snippets.

View tomciopp's full-sized avatar

Thomas Cioppettini tomciopp

View GitHub Profile
@tomciopp
tomciopp / My_Problem.txt
Created June 1, 2012 01:56
Devise with Wicked, after user signs up:
When a user signs up they are directed to a page that asks them to enter in their profile info
if they are a shipper or a carrier. I am unsure what to put in the new and create actions of the user_steps controller since I am creating two separate objects for the same controller. The actions for creating both of these objects should be exactly the same.
@tomciopp
tomciopp / registrations_controller.rb
Created May 31, 2012 23:43
Using devise with wicked for sign up wizards
class RegistrationsController < Devise::RegistrationsController
def create
build_resource
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
@tomciopp
tomciopp / _form.html.erb
Created May 30, 2012 21:16
Adding a datepicker to a nested form
<%= form_for(@load) do |f| %>
<%= f.error_messages %>
<%= f.fields_for :destinations do |builder| %>
<%= render "destination_fields", :f => builder %>
<% end %>
<p><%= link_to_add_fields " Add Destination", f, :destinations %></p>
<% end %>
_destination_fields.html.erb
def index
@facets = Load.facets(
(params[:trucks]),
:page => (params[:page] || 1),
:per_page => 25,
:geo => degrees_to_radians(@location),
:with => { "@geodist" => 0.0..miles_to_meters(params[:radius].to_i) },
:sort_mode => :expr,
:order => sort_by_select(params[:sort])
)
Models with their associations
class Reservation < ActiveRecord::Base
belongs_to :load
has_one :bid
end
class Load < ActiveRecord::Base
has_many :bids, :dependent => :delete_all
has_one :reservation
@tomciopp
tomciopp / gist:2574174
Created May 2, 2012 05:41
calling the geocoding method
Here is the test I have written:
// Another factory is created before this with the same address
it "should not call the geocoding method but should grab data from the database" do
@dest3 = FactoryGirl.create(:destination)
@dest3.should_not_receive(:geocoding)
end
// This method should fail but it passes
def find_coordinates
@tomciopp
tomciopp / gist:2425335
Created April 20, 2012 02:10
Observer not working
Here is an example record from the database before I have added a bid:
SELECT "loads".* FROM "loads" WHERE "loads"."id" = $1 LIMIT 1 [["id", 25]]
=> #<Load id: 25, commodity: "Coca-Cola", price: #<BigDecimal:103fb82c8,'0.4E3',9(18)>, weight: 30000, notes: "", created_at: "2012-04-17 22:41:53", updated_at: "2012-04-17 22:41:53", distance: 2733.36707093163, truck_type: "53' Dry Van", latitude: 0.651560856964623, longitude: -2.12983434097684, user_id: 5, delta: false, current_asking_price: nil>
Then we create a bid on that load with the following log:
Started POST "/loads/25/bids" for 127.0.0.1 at 2012-04-19 22:07:53 -0400
Processing by BidsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"iHCqQR68t9mrVZ3y5r3/ZMSZY++ZckIAJYwb2GGD3gg=", "bid"=>{"bid_price"=>"200", "questions"=>""}, "commit"=>"Create Bid", "load_id"=>"25"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 15 LIMIT 1
@tomciopp
tomciopp / gist:1842518
Created February 16, 2012 06:04
showing git branch in terminal
function parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NO_COLOUR="\[\033[0m\]"
PS1="$GREEN\[[TC]$NO_COLOUR:\w$YELLOW\$(parse_git_branch)$NO_COLOUR\$ "
@tomciopp
tomciopp / gist:1805852
Created February 12, 2012 02:25
Sinatra contact form
-------------------------------
The code for the contact form
-------------------------------
<div id='contact-box' class="group">
<div class="span6 clear">
<form action="/" method="post" class="well">
<label for="name">Your Name:</label>
<input type="text" name="name" class="span4" placeholder="John Smith...">
<label for="email">Your email address:</label>
the contact form
=========================================================
<div id='contact-box' class="group">
<div class="span6 clear">
<form action="/contact" method="post" class="well">
<label for="name">Your Name:</label>
<input type="text" class="span4" placeholder="John Smith...">
<label for="email">Your email address:</label>
<input type="email" class="span4" placeholder="email@example.com">