Skip to content

Instantly share code, notes, and snippets.

View ch1ago's full-sized avatar
🏠
Working mostly from home since 2006

Thiago Almeida ch1ago

🏠
Working mostly from home since 2006
  • Mexico City
  • 00:43 (UTC -06:00)
View GitHub Profile
@ch1ago
ch1ago / gist:1887901
Created February 22, 2012 22:23
isntalling gem pg
[user@red ~]$ gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/user/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
<style>
body {
margin: 0px;
padding: 0px;
}
#myCanvas {
border: 1px solid red;
width: 99.9%;
height: 1000px;
belongs_to :gift
belongs_to :user
class Post
def youtube_url=(value)
self.youtube=value.gsub("http://.../","")
end
def youtube_url
youtube
end
end
@ch1ago
ch1ago / gist:2368818
Created April 12, 2012 16:24
current_user performance :)
Hey guys, since current_user is a method used in every request I decided to give it a few benchmarks
I'm gisting this so if anyone may find good literature
here was my start point question:
which is best?
(yes this approach doesn't validate an auth token)
def current_user
if session[:user_id]
SELECT `sales`.* FROM `sales`
INNER JOIN `properties` ON `properties`.`id` = `sales`.`property_id`
WHERE (properties.zip = 33160)
ORDER BY sale_date DESC
LIMIT 10
Duration 56,163 ms
Explain
Failures:
1) SessionsController GET 'destroy' returns http success
Failure/Error: get 'destroy'
NameError:
undefined local variable or method `root_path' for #<SessionsController:0x9c8a088>
# ./app/controllers/sessions_controller.rb:20:in `destroy'
# ./spec/controllers/sessions_controller_spec.rb:18:in `block (3 levels) in <top (required)>'
2) users/index renders a list of users
Fabricator(:state) do
name { Faker::Address.city }
end
Fabricator(:city) do
state #{ Fabricate(:state) }
name { Faker::Address.city }
end
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user
can :read, Band
can :create, Band do |band|
user.persisted?
end
require 'spec_helper'
describe "bands/show" do
before(:each) do
@band = assign(:band, Fabricate(:band))
end
it "renders page" do
render
end