Skip to content

Instantly share code, notes, and snippets.

spec/support/authentication.rb
def login!(user = false)
@current_user = user
controller.stub!(:current_user).and_return(@current_user)
view.stub!(:current_user).and_return(@current_user)
session[:user_id] = @current_user.id
end
def login_as_seller!(seller = Seller.make(:valid))
@23inhouse
23inhouse / route_set.rb
Created September 5, 2011 03:06
ActionDispatch::Routing::RouteSet::Generator#initialize_with_baby_unicorn_killer
# this is a hack to get the subdomain part of routing working
# I added it in for Rails 3.0.1
module ActionDispatch
module Routing
class RouteSet
class Generator
alias_method :initialize_before, :initialize
def initialize(options, recall, set, extras = false)
initialize_before(options, recall, set, extras)
@recall.delete(:subdomain)
- app
- controllers
- seller # namespaced like an admin but for sellers
whatevere.rb # must have a file in here
- models
seller.rb
$ rspec spec
Exception encountered: #<RuntimeError: Already memoized foobar> # foobar is inside models/seller.rb
@23inhouse
23inhouse / follow.rb
Created August 25, 2012 01:58
Find twitter and facebook accounts
require 'mechanize'
require 'twitter'
require 'csv'
csv = CSV.open("./output.csv", "w")
# CSV Headers
csv << ["Winery Name", "Twitter Title", "Twitter Link", "Facebook Title", "Facebook Link"]
#wineries = ["novavitawines", "Wicks Estate Wines", "Izway Wines"]
@23inhouse
23inhouse / follow.rb
Created August 29, 2012 02:32 — forked from phoozle/follow.rb
Find twitter and facebook accounts
#!/usr/bin/env ruby
require 'mechanize'
require 'csv'
require 'fileutils'
source_csv = ARGV[0] || "./wineries.csv"
max_searchs = ARGV[1] || 100
def google_site_search(site, query)
@23inhouse
23inhouse / gist:3547823
Created August 31, 2012 02:04
following twitter
require 'mechanize'
require 'csv'
CSV.foreach('wineries.csv', "r") do |row|
puts row.first
end
@23inhouse
23inhouse / gist:3594537
Created September 2, 2012 03:24
Simple form mappings

Config

# config/initializers/simple_form.rb

SimpleForm.setup do |config|
  config.wrappers :default,
                  :class => 'input',
                  :hint_class => 'field_with_hint',
                  :error_class => 'field_with_errors' do |b|
@23inhouse
23inhouse / gist:3594808
Created September 2, 2012 04:18
Customizing simple_form and bootstrap

Customization

<%= f.input :state, :collection => ['SA', 'WA'] %>
<%= f.input :state,
            :as => :radio_buttons,
            :collection => ['SA', 'WA'],
@23inhouse
23inhouse / gist:3594973
Created September 2, 2012 05:06
1 more thing

Further customization

bundle open simple_form
<!-- app/view/blogs/_form.html.erb -->

<%= simple_form_for @blog, :html => { :class => 'form-horizontal' } do |f| %>