Skip to content

Instantly share code, notes, and snippets.

@dannymcc
dannymcc / gist:2857502
Created June 2, 2012 09:23
Acumen Nav Before or Nav After
<li class="level0 level-top">
<a href="http://acumen-magento.gravdept.com/tour/">Acumen Tour</a>
<div class="menu">
<ul class="level0">
<li class="level1"><a href="http://acumen-magento.gravdept.com/tour/features/">Features</a></li>
<li class="level1"><a href="http://acumen-magento.gravdept.com/tour/design/">Design</a></li>
<li class="level1"><a href="http://acumen-magento.gravdept.com/tour/ui-widgets/">UI Widgets</a></li>
<li class="level1"><a href="http://acumen-magento.gravdept.com/tour/snippets/">Snippets</a></li>
<li class="level1"><a href="http://acumen-magento.gravdept.com/tour/grid/">Grid System</a></li>
<div class="grid">
<div class="grid_6">
{{block type=”catalog/product_new” column_count=”2” label=”New Products” template=”gravdept/catalog/new-products-slider.phtml” }}
</div>
<div class="grid_6">
{{block type=”catalog/product_list” category_id=”73” column_count=”2” label=”Featured Products” template=”gravdept/catalog/category-slider.phtml” }}
</div>
</div>
class ApplicationController < ActionController::Base
before_filter :protect
protect_from_forgery
def protect
@ips = ['127.0.0.1', '116.155.117.121']
if not @ips.include? request.remote_ip
# Check for your subnet stuff here, for example
# if not request.remote_ip.include?('127.0,0')
render :text => "You are unauthorized"
@dannymcc
dannymcc / document_system
Created July 19, 2012 12:16
Documents with Categories and Tags
documents
has_and_belongs_to_many :category
has_and_belongs_to_many :tags
has_many :attachments, :dependent => :destroy
categories
has_and_belongs_to_many :documents
tags
has_and_belongs_to_many :documents
Jul 23 12:08:01 Ubuntu-1104-natty-64-minimal CRON[9913]: (CRON) error (grandchild #9915 failed with exit status 127)
Jul 23 12:08:01 Ubuntu-1104-natty-64-minimal CRON[9913]: (CRON) info (No MTA installed, discarding output)
@dannymcc
dannymcc / application_controller.rb
Created July 24, 2012 19:57
Protect from all but whitelist
before_filter :protect
def protect
@ips = ['127.0.0.1', '192.168.1.0/24'] #And so on ...]
allowed = false
@ips.each do |ipstring|
ip, mask = ipstring.split '/'
mask = mask ? mask.to_i : 32
bip = 0
ip.split('.').each { |x| bip = (bip << 8) + x.to_i }
@dannymcc
dannymcc / invoice_controller.rb
Created August 1, 2012 08:34
Mark invoice as Paid
class InvoicesController < InheritedResources::Base
custom_actions :resource => :mark_paid
def show
show! do |format|
format.html
format.pdf do
send_data(@invoice.render_pdf, :filename => "Invoice #{@invoice.id}.pdf", :type => "application/pdf", :disposition => "inline")
end
end
class Invoice < ActiveRecord::Base
validate :expiration_date_cannot_be_in_the_past,
:discount_cannot_be_greater_than_total_value
def expiration_date_cannot_be_in_the_past
if !expiration_date.blank? and expiration_date < Date.today
errors.add(:expiration_date, "can't be in the past")
end
end
# encoding: utf-8
class FaxUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
# Use this hook to configure devise mailer, warden hooks and so forth.
# Many of these configuration options can be set straight in your model.
Devise.setup do |config|
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
config.mailer_sender = "admin@cargosurveyors.com"
config.case_insensitive_keys = [ :username ]
config.strip_whitespace_keys = [ :username ]