Skip to content

Instantly share code, notes, and snippets.

Avatar

Philip Ingram pjammer

View GitHub Profile
View gist:181802
#controller method
@affiliates = @shop.affiliates.paginate(:page => params[:page], :order => "id desc", :include => :user)
#view trouble spot
<% for affiliate in @affiliates %>
<tr>
<td><%= link_to affiliate.user.email, admin_affiliate_path(affiliate) %></td>
</tr>
<% end %>
@pjammer
pjammer / gist:184222
Created Sep 10, 2009
Trying to move controller code to model code
View gist:184222
#Model Code
def self.calculate_state_revenue(state)
@affiliates = select_state(state) # gets all affiliates from the state
@orders_unpaginated = self.orders
#use inject to add up their order totals.
@state_total = @affiliates.inject {|result, affiilate|
result = @orders_unpaginated.calculate(:sum, "order_total", :conditions => ['affiliate_code = ?', affiliate.affiliate_code])
result
}
View snippet.rb
require 'test_helper'
class AuthenticationTest < ActionController::IntegrationTest
def log_and_say(user, arg)
login_on_admin(user.username, user.password)
assert_content arg
end
test "Login on admin with valid username, password and role" do
user = Factory.build(:user_admin)
log_and_say(user, "Welcome #{user.username}, logged in as #{user.role}")
View snippet.rb
class Post
has_many :comments
has_many :tags, :as => :taggable
class Comment
belongs_to :post
has_many :tags, :as => :taggable
class Tag
belongs_to :taggable, :polymorphic => true
@pjammer
pjammer / partial_init.el
Created Jul 11, 2011
how i get el-get working
View partial_init.el
;; el-get sourcing
(add-to-list 'load-path "~/.emacs.d/el-get")
(require 'el-get)
(setq el-get-sources
'(el-get
package
yasnippet
color-theme
color-theme-ir-black
color-theme-chocolate-rain
@pjammer
pjammer / eunic
Created Feb 9, 2012
i put this into /usr/local/bin/eunic and you can your server using eunic -s && eunic -N
View eunic
#!/bin/bash
set -u
set -e
#change this below to your actual path. If you another environemnt like staging, fucking change N to -e staging instead.
APP_PATH=/youpath/to/app/root
PID=$APP_PATH/tmp/pids/unicorn.pid
OLD_PID=$APP_PATH/tmp/pids/unicorn.pid.oldbin
UNICORN_COMMAND="unicorn_rails -c $APP_PATH/config/unicorn.rb -D"
while getopts ":nsNr" opt; do
You can’t perform that action at this time.