Skip to content

Instantly share code, notes, and snippets.

View spacecowb0y's full-sized avatar

Diego spacecowb0y

View GitHub Profile
Mysql2::Error: Unknown column 'orders.projects' in 'where clause': SELECT COUNT(*) FROM `invoices` INNER JOIN `orders` ON `orders`.`id` = `invoices`.`order_id` INNER JOIN `projects` ON `projects`.`id` = `orders`.`project_id` WHERE `orders`.`projects` = '---\n:user_id: 283\n' AND `invoices`.`status` = 1
@spacecowb0y
spacecowb0y / order.rb
Created January 18, 2013 04:02
God bless AR!
class Order < ActiveRecord::Base
## Setup accessible (or protected) attributes for your model
attr_accessible :project_id, :developer_id, :due_date, :status, :notes, :is_delivered, :deliveted_at, :completed_at
## Virtual attributes
attr_accessor :pages
## Associations
belongs_to :project
@spacecowb0y
spacecowb0y / examples.rb
Last active December 11, 2015 17:48
Sexy methods for AR objects.
def unread_comments
readable_comments.delete_if {|c| c.created_at < c.discussion.assignments.find_by_user_id(id).updated_at }
end
def create_new_invoice!
invoice = invoices.build
order_item_options.delete_if{ |o| o.price == 0 }.map{ |o| invoice.invoice_lines.build(:order_item_id => o.order_item.id, :description => o.order_item.name, :unit_price => o.price) }
invoice.save!
end
@spacecowb0y
spacecowb0y / gmail_will_paginate.rb
Created February 4, 2013 14:31
Gmail pagination style with Will Paginate
# config/initializers/gmail_will_paginate.rb
# USAGE:
# <%= will_paginate(@posts, :renderer => WillPaginate::Gmail) %>
module WillPaginate
class Gmail < ::WillPaginate::ActionView::LinkRenderer
def pagination
[:window, :pagination_buttons]
end
#
# This is the main Apache HTTP server configuration file. It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.2> for detailed information.
# In particular, see
# <URL:http://httpd.apache.org/docs/2.2/mod/directives.html>
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure
Started PUT "/manager/projects/1" for 127.0.0.1 at 2013-05-07 19:32:00 -0300
Processing by Manager::ProjectsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"chEAfffsI3HcHlPqBn0LfQxIO/V7DhXj6wQ2j3jSIi8=", "project"=>{"milestones_attributes"=>{"0"=>{"pages"=>"1", "budget"=>"2", "development_cost_amount"=>"3", "developer_id"=>"1", "is_completed"=>"1", "is_delivered"=>"0"}}}, "commit"=>"Save", "id"=>"1"}
Project Load (0.3ms) SELECT `projects`.* FROM `projects` WHERE `projects`.`id` = 1 LIMIT 1
(0.1ms) BEGIN
SQL (0.3ms) INSERT INTO `activities` (`created_at`, `key`, `owner_id`, `owner_type`, `parameters`, `recipient_id`, `recipient_type`, `trackable_id`, `trackable_type`, `updated_at`) VALUES ('2013-05-07 22:32:00', 'project.update', NULL, NULL, '--- {}\n', NULL, NULL, 1, 'Project', '2013-05-07 22:32:00')
SQL (5.9ms) INSERT INTO `project_milestones` (`budget`, `created_at`, `developer_id`, `development_cost_amount`, `is_completed`, `is_delivered`, `pages`, `project_id`, `up
RewriteEngine on
# Hide Directories
Options -Indexes
# Redirects
ErrorDocument 404 http://www.pixel2html.net/
ErrorDocument 401 http://www.pixel2html.net/
ErrorDocument 403 http://www.pixel2html.net/
RewriteCond %{HTTP_HOST} ^pixel2wp.com$ [OR]
Backend::Application.routes.draw do
namespace :manager do
resources :projects do
scope :module => "projects" do
resources :activities, as: 'activity', path: 'activity', only: [:index, :destroy]
resources :milestones
resources :tickets
resources :invoices
<div class="day">
<ul>
<% date = Time.now+1.day %>
<% price = 150 %>
<% 7.times do |i| %>
<% date += 1.day %>
<% price -= 10 %>
<% if date.strftime("%u").to_i > 5 %>
<% date = date+2.day %>
<% end %>
@spacecowb0y
spacecowb0y / Vagrantfile
Last active January 19, 2017 00:09
Vagrant config to setup a rvm + ruby + rails + passenger + nginx + mysql.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.network :forwarded_port, guest: 3000, host: 3000
config.vm.hostname = "ruby-dev-server"
config.vm.provision :shell, path: "install.sh"