Skip to content

Instantly share code, notes, and snippets.

View safarista's full-sized avatar

Nelson Kelem safarista

View GitHub Profile
@safarista
safarista / person.rb
Created September 3, 2012 18:23
Trying to replicate God Almighty on the 6th day of the creation theorem
# encoding: utf-8
# and afetr he had created everything and saw it was good
# ..."On the 6th day he made man and rested on the 7th day"
# so lets make some babies
class Person
def initialize(names, age, gender, status, job = 'Jobless for now')
@names = names
@age = age
@safarista
safarista / directory.rb
Created September 3, 2012 16:59
Seeding a database using CSV module. A complete noob style.
# encoding: utf-8
#
# The job here was to seed the database with
# A mega list of business directory
# the directories have subdirectories
# The result is found on http://enterprisesthelena.com/directories
# What do you think? Is there a better way to do it?
require 'ap'
require 'csv'
@safarista
safarista / irb3.rb
Created July 27, 2012 16:20
Why is the gem term-ansicolor not found in my path? I have it in the global gemset for 1.9.2
Nelsons-MacBook-Pro:triplexxx the-crab$ ruby xxx.rb
> 1 + 1
/Users/the-crab/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- term/ansicolor (LoadError)
from /Users/the-crab/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /var/folders/vl/th7n8fdx6yv7npscx0qsvyhh0000gn/T/irb320120727-1310-18zk341:3
1.8.7 =>
1.9.2 => 2
/Users/the-crab/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- term/ansicolor (LoadError)
from /Users/the-crab/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /var/folders/vl/th7n8fdx6yv7npscx0qsvyhh0000gn/T/irb320120727-1310-18zk341:3:in `<main>'
@safarista
safarista / testcase.rb
Created October 14, 2011 16:21
Is there a reason why you would require then include a resource at the same time? i.e. Assertions
require 'test/unit/assertions'
module Test
module Unit
# remove silly TestCase class
remove_const(:TestCase) if defined?(self::TestCase)
class TestCase < MiniTest::Unit::TestCase
include Assertions
def self.test_order
@safarista
safarista / order.rb
Created October 10, 2011 20:54
am trying to do the buying, and sending email to user and notifications to admin
class Order < ActiveRecord::Base
has_many :line_items, :dependent => :destroy
belongs_to :user
attr_accessor :card_number, :card_type, :card_verification, :card_expires_on, :first_name, :last_name, :name, :address1,:city, :county, :country, :post_code
#VALIDATIONS
validate :validate_card, :on => :create
validate :card_verification, :presence => true
@safarista
safarista / cart_controller.rb
Created October 5, 2011 19:01
I am trying to set more than one id in the add action.
class CartController < ApplicationController
before_filter :login_required
before_filter :find_cart
def add
@cart.save if @cart.new_record?
session[:cart_id] = @cart.id
recipe = Recipe.find(params[:id])
LineItem.create! :order => @cart, :recipe => recipe, :price => recipe.price
@cart.recalculate_price!
@safarista
safarista / recipes.rb
Created September 20, 2011 21:55
Trying to find recipes based on the user from the url, maybe wrong but its same as using current_user.id. Also why the "Show" path is not working though the url is. Rails 3.1.0
#/app/views/recipes/index.html.erb
#ERROR: undefined method `each' for #<Recipe:0x00000102e88a20>
<% @recipes.each do |recipe| %>
<tr>
<td>0001</td>
<td><%= recipe.name %></td>
<td><%= recipe.status %></td>
<td><%= recipe.due_on.strftime('%d %B') %></td>
<td><%= link_to "Show", user_recipe_path(recipe) %></td>
<h2>Log In</h2>
<%= form_tag sessions_path do %>
<div class="field">
<%= label_tag :user_name %><br>
<%= text_field_tag :user_name, params['user_name'] %>
</div>
<p></p>
<div class="field">
<%= label_tag :password %><br/>
class SessionsController < ApplicationController
def new
if member = Member.find_by_password_digest(cookies[:digest])
session[:member_id] = member.id
redirect_to (session[:ref] || root_path), :notice => "Welcome back #{member.first_name}"
end
end
def create
class ApplicationController < ActionController::Base
protect_from_forgery
def current_ability
@current_ability ||= Ability.new(current_member)
end
rescue_from CanCan::AccessDenied do |exception|
flash[:alert] = "Access Denied."
redirect_to root_url