Skip to content

Instantly share code, notes, and snippets.

View gertig's full-sized avatar

Andrew Gertig gertig

View GitHub Profile
class NewMailer < ActionMailer::Base
default :from => "sendersemail@gmail.com"
require "net/http"
def registration_confirmation(person, thepage, email)
@person = person #Mailers are similar to Controllers as instance variables are passed to the View layer
@thepage = thepage
attachments["rails.png"] = File.read("#{Rails.root}/public/images/rails.png") #Used to test attachments, remove in production
attachments["#{thepage.id}.pdf"] = {:content => email }
<p id="notice"><%= notice %></p>
<p id="show_item"><%= link_to "Email This Page to User", mailit_thepage_path(@thepage) %></p>
<p id="show_item"><%= link_to "Download This Page as a PDF", thepage_path(@thepage, :format => "pdf")%></p>
<p id="show_item">
<b>Person's Name:</b>
<%= Person.find(@thepage.person_id).name %>
</p>
class ThepagesController < ApplicationController
#Gertig Mailer Method
def mailit
#Used to send an email to user when they are created
#To make this action RESTful you should add the following to your routes.rb file (uncommented of course)
#resources :thepages do
# member do
$ rails generate scaffold email_subscriber first_name:string last_name:string email:string
$ rake db:migrate
/*Opacity*/
filter: alpha(opacity=80); /* internet explorer */
-khtml-opacity: 0.8; /* khtml, old safari */
-moz-opacity: 0.8; /* mozilla, netscape */
opacity: 0.8; /* fx, safari, opera */
/*Rounded Corners*/
-moz-border-radius: 10px; /* Firefox */
-webkit-border-radius: 10px; /* Safari, Chrome */
border-radius: 10px; /* CSS3 */
@gertig
gertig / very_useful.rb
Created February 1, 2011 04:53
Snippets of code that are very useful in .rb files in Rails
#application_controller.rb
rescue_from CanCan::AccessDenied do |exception|
flash[:error] = "Access Denied"
redirect_to root_url
end
#application_helper.rb
def javascript(*files)
content_for(:head) { javascript_include_tag(*files)}
end
@gertig
gertig / scheduler.rb
Created February 6, 2011 01:43
Rails 3 demo of using HTTParty and Moment for delayed jobs
# models/scheduler.rb
require 'httparty'
require 'pp'
MOMENT_API_KEY = 'XXXXXXXXXXXXX'
class Scheduler
include HTTParty
base_uri 'https://momentapp.com'
@gertig
gertig / custom_controller.rb
Created February 6, 2011 01:43
Rails 3 demo of using HTTParty and Moment for delayed jobs
# controllers/custom_controller.rb
class CustomController < ApplicationController
def index
Person.create_schedule
end
def mycustomaction
#Do Something with the user_id
@gertig
gertig / routes.rb
Created February 6, 2011 01:40
Rails 3 demo of using HTTParty and Moment for delayed jobs
# config/routes.rb
MyApp::Application.routes.draw do
resources :people
resources :custom
resources :custom do
member do
get 'mycustomaction'
@gertig
gertig / person.rb
Created February 6, 2011 01:44
Rails 3 demo of using HTTParty and Moment for delayed jobs
#models/person.rb
class Person < ActiveRecord::Base
def self.create_schedule
@people = Person.find(:all)
time_increment = 1 #Starts the first scheduled task for 1 minute from now.
@people.each do |person|