├── log └── .gitkeep ├── lib ├── tasks │ └── .gitkeep └── assets │ └── .gitkeep ├── public ├── favicon.ico ├── robots.txt ├── 500.html ├── 422.html └── 404.html ├── app ├── mailers │ └── .gitkeep ├── models │ ├── .gitkeep │ ├── lead.rb │ ├── opportunity.rb │ ├── contact.rb │ ├── account.rb │ ├── salesforce_model.rb │ └── rails_user.rb ├── helpers │ └── application_helper.rb ├── assets │ ├── images │ │ └── rails.png │ ├── stylesheets │ │ └── application.css │ └── javascripts │ │ └── application.js ├── controllers │ ├── application_controller.rb │ └── salesforce_controller.rb └── views │ ├── salesforce │ ├── contacts.html.erb │ ├── account.html.erb │ └── accounts.html.erb │ └── layouts │ └── application.html.erb ├── vendor ├── plugins │ └── .gitkeep └── assets │ ├── javascripts │ └── .gitkeep │ └── stylesheets │ └── .gitkeep ├── config.ru ├── config ├── environment.rb ├── boot.rb ├── initializers │ ├── mime_types.rb │ ├── cloudconnect.rb │ ├── backtrace_silencers.rb │ ├── session_store.rb │ ├── secret_token.rb │ ├── wrap_parameters.rb │ ├── inflections.rb │ └── devise.rb ├── locales │ ├── en.yml │ └── devise.en.yml ├── environments │ ├── test.rb │ ├── development.rb │ └── production.rb ├── database.yml ├── routes.rb └── application.rb ├── doc └── README_FOR_APP ├── Rakefile ├── script ├── rails └── inserts.rb ├── db ├── seeds.rb ├── schema.rb └── migrate │ └── 20140121225800_add_devise_to_rails_users.rb ├── .gitignore ├── Gemfile ├── README.rdoc └── Gemfile.lock /log/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/tasks/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/mailers/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/models/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/plugins/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/assets/javascripts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/assets/stylesheets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/models/lead.rb: -------------------------------------------------------------------------------- 1 | class Lead < SalesforceModel 2 | self.table_name = 'lead__c' 3 | end 4 | -------------------------------------------------------------------------------- /app/assets/images/rails.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyric/herokuconnectdemo/master/app/assets/images/rails.png -------------------------------------------------------------------------------- /app/models/opportunity.rb: -------------------------------------------------------------------------------- 1 | class Opportunity < SalesforceModel 2 | self.table_name = 'opportunity' 3 | 4 | attr_protected :CreatedDate, :SystemModstamp, :LastModifiedDate 5 | end 6 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery 3 | 4 | before_filter :authenticate_rails_user! 5 | 6 | end 7 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Cloudconnectdemo::Application 5 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the rails application 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the rails application 5 | Cloudconnectdemo::Application.initialize! 6 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | 3 | # Set up gems listed in the Gemfile. 4 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 5 | 6 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) 7 | -------------------------------------------------------------------------------- /doc/README_FOR_APP: -------------------------------------------------------------------------------- 1 | Use this README file to introduce your application and point to useful places in the API for learning more. 2 | Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries. 3 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-Agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | # Mime::Type.register_alias "text/html", :iphone 6 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Sample localization file for English. Add more files in this directory for other locales. 2 | # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. 3 | 4 | en: 5 | hello: "Hello world" 6 | -------------------------------------------------------------------------------- /config/initializers/cloudconnect.rb: -------------------------------------------------------------------------------- 1 | ENV['CLOUDCONNECT_URL'] = 'postgresql://sync_c5master_1:a7002977e749@localhost/t1_scottpersingeratgmailcom' 2 | #postgres://vveyuqgafibygf:ZEJmD8AK-LhydRExqm0S4wKRJw@ec2-54-225-218-144.compute-1.amazonaws.com:5442/d8jltj3rrp5pln' -------------------------------------------------------------------------------- /app/models/contact.rb: -------------------------------------------------------------------------------- 1 | class Contact < SalesforceModel 2 | self.table_name = ENV['HEROKUCONNECT_SCHEMA'] + '.contact' 3 | belongs_to :account, :primary_key => 'sfid', :foreign_key => 'accountid' 4 | 5 | attr_protected :createddate, :systemmodstamp, :lastmodifieddate 6 | end 7 | -------------------------------------------------------------------------------- /app/models/account.rb: -------------------------------------------------------------------------------- 1 | class Account < SalesforceModel 2 | self.table_name = ENV['HEROKUCONNECT_SCHEMA'] + '.account' 3 | 4 | has_many :contacts, :primary_key => "sfid", :foreign_key => "accountid" 5 | 6 | attr_protected :CreatedDate, :SystemModstamp, :LastModifiedDate 7 | end 8 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | # Add your own tasks in files placed in lib/tasks ending in .rake, 3 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 4 | 5 | require File.expand_path('../config/application', __FILE__) 6 | 7 | Cloudconnectdemo::Application.load_tasks 8 | -------------------------------------------------------------------------------- /script/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. 3 | 4 | APP_PATH = File.expand_path('../../config/application', __FILE__) 5 | require File.expand_path('../../config/boot', __FILE__) 6 | require 'rails/commands' 7 | -------------------------------------------------------------------------------- /script/inserts.rb: -------------------------------------------------------------------------------- 1 | # Generate interleaved inserts 2 | 3 | 400.times do 4 | Account.create(:name => "Big Co 600") 5 | Contact.create(:firstname => 'Dr', :lastname=>'Rosenpenis') 6 | Lead.create(:name=>'Scott Persinger') 7 | Opportunity.create(:name => "This is a great chance at a sale", :stagename=>'Prospecting', :closedate=>'2013-12-31') 8 | end 9 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) 7 | # Mayor.create(name: 'Emanuel', city: cities.first) 8 | -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Cloudconnectdemo::Application.config.session_store :cookie_store, key: '_cloudconnectdemo_session' 4 | 5 | # Use the database for sessions instead of the cookie-based default, 6 | # which shouldn't be used to store highly confidential information 7 | # (create the session table with "rails generate session_migration") 8 | # Cloudconnectdemo::Application.config.session_store :active_record_store 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile ~/.gitignore_global 6 | 7 | # Ignore bundler config 8 | /.bundle 9 | 10 | # Ignore the default SQLite database. 11 | /db/*.sqlite3 12 | 13 | # Ignore all logfiles and tempfiles. 14 | /log/*.log 15 | /tmp 16 | -------------------------------------------------------------------------------- /app/views/salesforce/contacts.html.erb: -------------------------------------------------------------------------------- 1 |

Salesforce Contacts

2 | 3 | 4 | 5 | 6 | <% @contacts.each do |contact| %> 7 | 8 | 9 | 10 | 11 | 12 | <% end %> 13 |
NameDateSalesforce Id
<%= contact.firstname %> <%= contact.lastname %><%= contact.createddate.strftime("%d %b %y") %><%= contact.sfid %>
14 | 15 | <%= link_to 'prev', {:page => @page-1} %> | 16 | <%= link_to 'next', {:page => @page+1} %> 17 | -------------------------------------------------------------------------------- /config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | # Make sure the secret is at least 30 characters and all random, 6 | # no regular words or you'll be exposed to dictionary attacks. 7 | Cloudconnectdemo::Application.config.secret_token = '4bcfc25a9d6b4103600f3d271e4e5a78c344dd54b80a673035e68fe687e60555f24f4609636c488cba71df1ea2951eb27d78468e8a880f9e823e37f35ba24941' 8 | -------------------------------------------------------------------------------- /app/views/salesforce/account.html.erb: -------------------------------------------------------------------------------- 1 |

Account: <%= @account.name %>

2 | 3 |

Contacts

4 | 5 | 6 | 7 | 8 | <% @contacts.each do |contact| %> 9 | <% next if contact.nil? %> 10 | 11 | 12 | 13 | 14 | 15 | 16 | <% end %> 17 |
idNameEmailPhone
<%= contact.id %><%= contact.firstname %> <%= contact.lastname %><%= contact.email %><%= contact.phone %>
-------------------------------------------------------------------------------- /config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # Disable root element in JSON by default. 12 | ActiveSupport.on_load(:active_record) do 13 | self.include_root_in_json = false 14 | end 15 | -------------------------------------------------------------------------------- /app/views/salesforce/accounts.html.erb: -------------------------------------------------------------------------------- 1 |

Salesforce Accounts

2 | 3 | 4 | 5 | 6 | <% @accounts.each do |account| %> 7 | 8 | 9 | 10 | 11 | 12 | 13 | <% end %> 14 |
NameDateSalesforce Id
<%= account.name %><%= account.createddate.strftime("%d %b %y") %><%= account.sfid %><%= link_to "details", "/account/#{account.id}" %>
15 | 16 | <%= link_to 'prev', {:page => @page-1} %> | 17 | <%= link_to 'next', {:page => @page+1} %> 18 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format 4 | # (all these examples are active by default): 5 | # ActiveSupport::Inflector.inflections do |inflect| 6 | # inflect.plural /^(ox)$/i, '\1en' 7 | # inflect.singular /^(ox)en/i, '\1' 8 | # inflect.irregular 'person', 'people' 9 | # inflect.uncountable %w( fish sheep ) 10 | # end 11 | # 12 | # These inflection rules are supported but not enabled by default: 13 | # ActiveSupport::Inflector.inflections do |inflect| 14 | # inflect.acronym 'RESTful' 15 | # end 16 | -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the top of the 9 | * compiled file, but it's generally better to create a new file per style scope. 10 | * 11 | *= require_self 12 | *= require_tree . 13 | */ 14 | -------------------------------------------------------------------------------- /app/controllers/salesforce_controller.rb: -------------------------------------------------------------------------------- 1 | class SalesforceController < ApplicationController 2 | 3 | def accounts 4 | @page = (params[:page] || 1).to_i 5 | @accounts = Account.order("name").offset(@page*20).limit(20).all() 6 | end 7 | 8 | def account 9 | if params[:id] =~ /^\d+$/ 10 | @account = Account.find(params[:id]) 11 | else 12 | @account = Account.find_by_sfid(params[:id]) 13 | end 14 | 15 | begin 16 | @contacts = @account.contacts 17 | rescue 18 | @contacts = [] 19 | end 20 | end 21 | 22 | def contacts 23 | @page = (params[:page] || 1).to_i 24 | @contacts = Contact.order("lastname").offset(@page*20).limit(20).all() 25 | end 26 | 27 | end 28 | -------------------------------------------------------------------------------- /app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // the compiled file. 9 | // 10 | // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD 11 | // GO AFTER THE REQUIRES BELOW. 12 | // 13 | //= require jquery 14 | //= require jquery_ujs 15 | //= require_tree . 16 | -------------------------------------------------------------------------------- /public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

We're sorry, but something went wrong.

23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The change you wanted was rejected.

23 |

Maybe you tried to change something you didn't have access to.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The page you were looking for doesn't exist.

23 |

You may have mistyped the address or the page may have moved.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rails', '3.2.13' 4 | 5 | # Bundle edge Rails instead: 6 | # gem 'rails', :git => 'git://github.com/rails/rails.git' 7 | 8 | gem 'pg' 9 | gem 'devise' 10 | 11 | # Gems used only for assets and not required 12 | # in production environments by default. 13 | group :assets do 14 | gem 'sass-rails', '~> 3.2.3' 15 | 16 | # See https://github.com/sstephenson/execjs#readme for more supported runtimes 17 | # gem 'therubyracer', :platforms => :ruby 18 | 19 | gem 'uglifier', '>= 1.0.3' 20 | end 21 | 22 | gem 'jquery-rails' 23 | 24 | # To use ActiveModel has_secure_password 25 | # gem 'bcrypt-ruby', '~> 3.0.0' 26 | 27 | # To use Jbuilder templates for JSON 28 | # gem 'jbuilder' 29 | 30 | # Use unicorn as the app server 31 | # gem 'unicorn' 32 | 33 | # Deploy with Capistrano 34 | # gem 'capistrano' 35 | 36 | # To use debugger 37 | # gem 'debugger' 38 | -------------------------------------------------------------------------------- /app/models/salesforce_model.rb: -------------------------------------------------------------------------------- 1 | class SalesforceModel < ActiveRecord::Base 2 | self.abstract_class = true 3 | self.inheritance_column = 'rails_type' 4 | 5 | if ENV['HEROKUCONNECT_URL'].nil? 6 | puts "WARNING: YOU SHOULD SET HEROKUCONNECT_URL IN YOUR ENVIRONMENT" 7 | end 8 | if ENV['HEROKUCONNECT_SCHEMA'].nil? 9 | puts "WARNING: YOU SHOULD SET HEROKUCONNECT_SCHEMA IN YOUR ENVIRONMENT" 10 | end 11 | 12 | establish_connection ENV['HEROKUCONNECT_URL'] 13 | attr_protected :createddate, :systemmodstamp, :lastmodifieddate 14 | 15 | def hc_errors 16 | HerokuconnectTriggerLog.where(:record_id => self.id, :state => 'FAILED').order("id DESC").all 17 | end 18 | 19 | def hc_last_error 20 | errs = cc_errors() 21 | if errs[0] 22 | errs[0].sf_message 23 | else 24 | nil 25 | end 26 | end 27 | end 28 | 29 | class HerokuconnectTriggerLog < SalesforceModel 30 | self.table_name = '_trigger_log' 31 | 32 | def self.pending 33 | HerokuconnectTriggerLog.where(:state => 'NEW').count 34 | end 35 | 36 | end 37 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Cloudconnectdemo 5 | <%= stylesheet_link_tag "application", :media => "all" %> 6 | <%= javascript_include_tag "application" %> 7 | <%= csrf_meta_tags %> 8 | 18 | 19 | 20 | 21 | <% if rails_user_signed_in? %> 22 | Welcome <%= current_rails_user.salesforce_name %> (<%= current_rails_user.salesforce_id %> <%= current_rails_user.sf_error %>) 23 |
  • 24 | <%= link_to('Logout', destroy_rails_user_session_path, :method => :delete) %> 25 |
  • 26 | <% else %> 27 |
  • 28 | <%= link_to('Login', new_rails_user_session_path) %> 29 |
  • 30 | <% end %> 31 | 32 |

    <%= notice %>

    33 |

    <%= alert %>

    34 | 35 |

    cloudconnect Rails Demo

    36 | 37 |
    <%= link_to 'Accounts', '/accounts' %>
    38 |
    <%= link_to 'Contacts', '/contacts' %>
    39 |
    40 | 41 | <%= yield %> 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Cloudconnectdemo::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Configure static asset server for tests with Cache-Control for performance 11 | config.serve_static_assets = true 12 | config.static_cache_control = "public, max-age=3600" 13 | 14 | # Log error messages when you accidentally call methods on nil 15 | config.whiny_nils = true 16 | 17 | # Show full error reports and disable caching 18 | config.consider_all_requests_local = true 19 | config.action_controller.perform_caching = false 20 | 21 | # Raise exceptions instead of rendering exception templates 22 | config.action_dispatch.show_exceptions = false 23 | 24 | # Disable request forgery protection in test environment 25 | config.action_controller.allow_forgery_protection = false 26 | 27 | # Tell Action Mailer not to deliver emails to the real world. 28 | # The :test delivery method accumulates sent emails in the 29 | # ActionMailer::Base.deliveries array. 30 | config.action_mailer.delivery_method = :test 31 | 32 | # Raise exception on mass assignment protection for Active Record models 33 | config.active_record.mass_assignment_sanitizer = :strict 34 | 35 | # Print deprecation notices to the stderr 36 | config.active_support.deprecation = :stderr 37 | end 38 | -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # PostgreSQL. Versions 8.2 and up are supported. 2 | # 3 | # Install the pg driver: 4 | # gem install pg 5 | # On Mac OS X with macports: 6 | # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config 7 | # On Windows: 8 | # gem install pg 9 | # Choose the win32 build. 10 | # Install PostgreSQL and put its /bin directory on your path. 11 | # 12 | # Configure Using Gemfile 13 | # gem 'pg' 14 | # 15 | development: 16 | adapter: postgresql 17 | encoding: unicode 18 | database: spersinger 19 | pool: 5 20 | username: spersinger 21 | password: 22 | 23 | # Connect on a TCP socket. Omitted by default since the client uses a 24 | # domain socket that doesn't need configuration. Windows does not have 25 | # domain sockets, so uncomment these lines. 26 | host: localhost 27 | #port: 5432 28 | 29 | # Schema search path. The server defaults to $user,public 30 | #schema_search_path: myapp,sharedapp,public 31 | 32 | # Minimum log levels, in increasing order: 33 | # debug5, debug4, debug3, debug2, debug1, 34 | # log, notice, warning, error, fatal, and panic 35 | # The server defaults to notice. 36 | #min_messages: warning 37 | 38 | # Warning: The database defined as "test" will be erased and 39 | # re-generated from your development database when you run "rake". 40 | # Do not set this db to the same as development or production. 41 | test: 42 | adapter: postgresql 43 | encoding: unicode 44 | database: cloudconnectdemo_test 45 | pool: 5 46 | username: cloudconnectdemo 47 | password: 48 | 49 | production: 50 | adapter: postgresql 51 | encoding: unicode 52 | database: cloudconnectdemo_production 53 | pool: 5 54 | username: cloudconnectdemo 55 | password: 56 | -------------------------------------------------------------------------------- /app/models/rails_user.rb: -------------------------------------------------------------------------------- 1 | class RailsUser < ActiveRecord::Base 2 | # Include default devise modules. Others available are: 3 | # :confirmable, :lockable, :timeoutable and :omniauthable 4 | devise :database_authenticatable, :registerable, 5 | :recoverable, :rememberable, :trackable, :validatable 6 | 7 | # Setup accessible (or protected) attributes for your model 8 | attr_accessible :email, :password, :password_confirmation, :remember_me 9 | 10 | # attr_accessible :title, :body 11 | 12 | belongs_to :contact 13 | belongs_to :lead 14 | 15 | def self.match_contact_by_email(email) 16 | Contact.find_by_email(email) 17 | end 18 | 19 | def self.match_lead_by_email(email) 20 | Lead.find_by_email(email) 21 | end 22 | 23 | def salesforce_name 24 | if self.contact 25 | "#{self.contact.firstname} #{self.contact.lastname}" 26 | elsif self.lead 27 | "#{self.lead.firstname} #{self.lead.lastname}" 28 | else 29 | "" 30 | end 31 | end 32 | 33 | def salesforce_id 34 | self.contact ? self.contact.sfid : (self.lead ? self.lead.sfid : nil) 35 | end 36 | 37 | def sf_error 38 | if self.contact 39 | self.contact.cc_last_error 40 | elsif self.lead 41 | self.lead.cc_last_error 42 | end 43 | end 44 | 45 | def after_confirmation 46 | if self.contact.nil? && self.lead.nil? 47 | puts "No associated contact or lead" 48 | self.contact = RailsUser.match_contact_by_email(self.email) 49 | if self.contact.nil? 50 | self.lead = RailsUser.match_lead_by_email(self.email) 51 | end 52 | if self.contact.nil? && self.lead.nil? 53 | puts "Create a new lead" 54 | # Create a new Lead for this user 55 | self.lead = Lead.create(:email => self.email) 56 | end 57 | save() 58 | end 59 | end 60 | 61 | end 62 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | # This file is auto-generated from the current state of the database. Instead 3 | # of editing this file, please use the migrations feature of Active Record to 4 | # incrementally modify your database, and then regenerate this schema definition. 5 | # 6 | # Note that this schema.rb definition is the authoritative source for your 7 | # database schema. If you need to create the application database on another 8 | # system, you should be using db:schema:load, not running all the migrations 9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 10 | # you'll amass, the slower it'll run and the greater likelihood for issues). 11 | # 12 | # It's strongly recommended to check this file into your version control system. 13 | 14 | ActiveRecord::Schema.define(:version => 20140121225925) do 15 | 16 | create_table "my_users", :force => true do |t| 17 | t.datetime "created_at", :null => false 18 | t.datetime "updated_at", :null => false 19 | end 20 | 21 | create_table "rails_users", :force => true do |t| 22 | t.string "email", :default => "", :null => false 23 | t.string "encrypted_password", :default => "", :null => false 24 | t.string "reset_password_token" 25 | t.datetime "reset_password_sent_at" 26 | t.datetime "remember_created_at" 27 | t.integer "sign_in_count", :default => 0, :null => false 28 | t.datetime "current_sign_in_at" 29 | t.datetime "last_sign_in_at" 30 | t.string "current_sign_in_ip" 31 | t.string "last_sign_in_ip" 32 | end 33 | 34 | add_index "rails_users", ["email"], :name => "index_rails_users_on_email", :unique => true 35 | add_index "rails_users", ["reset_password_token"], :name => "index_rails_users_on_reset_password_token", :unique => true 36 | 37 | end 38 | -------------------------------------------------------------------------------- /db/migrate/20140121225800_add_devise_to_rails_users.rb: -------------------------------------------------------------------------------- 1 | class AddDeviseToRailsUsers < ActiveRecord::Migration 2 | def self.up 3 | create_table :rails_users do |t| 4 | ## Database authenticatable 5 | t.string :email, :null => false, :default => "" 6 | t.string :encrypted_password, :null => false, :default => "" 7 | 8 | ## Recoverable 9 | t.string :reset_password_token 10 | t.datetime :reset_password_sent_at 11 | 12 | ## Rememberable 13 | t.datetime :remember_created_at 14 | 15 | ## Trackable 16 | t.integer :sign_in_count, :default => 0, :null => false 17 | t.datetime :current_sign_in_at 18 | t.datetime :last_sign_in_at 19 | t.string :current_sign_in_ip 20 | t.string :last_sign_in_ip 21 | 22 | ## Confirmable 23 | # t.string :confirmation_token 24 | # t.datetime :confirmed_at 25 | # t.datetime :confirmation_sent_at 26 | # t.string :unconfirmed_email # Only if using reconfirmable 27 | 28 | ## Lockable 29 | # t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts 30 | # t.string :unlock_token # Only if unlock strategy is :email or :both 31 | # t.datetime :locked_at 32 | 33 | 34 | # Uncomment below if timestamps were not included in your original model. 35 | # t.timestamps 36 | end 37 | 38 | add_index :rails_users, :email, :unique => true 39 | add_index :rails_users, :reset_password_token, :unique => true 40 | # add_index :rails_users, :confirmation_token, :unique => true 41 | # add_index :rails_users, :unlock_token, :unique => true 42 | end 43 | 44 | def self.down 45 | # By default, we don't want to make any assumption about how to roll back a migration when your 46 | # model already existed. Please edit below which fields you would like to remove in this migration. 47 | raise ActiveRecord::IrreversibleMigration 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | == Heroku Connect Rails Demo 2 | 3 | The Heroku Connect system synchronizes records in your Salesforce account with 4 | a relational database. This simple Rails application demonstrates some techniques 5 | for accessing Salesforce data from the Heroku Connect database. 6 | 7 | This application assumes that you have mapped your Account and Contact objects 8 | from Salesforce. This results in the "account" and "contact" tables being 9 | created in the Heroku Connect database. 10 | 11 | This application implements ActiveRecord models classes to talk to those tables, 12 | and adds some simple views for browsing those records. 13 | 14 | == Getting Started 15 | 16 | 1. Sign up for a Heroku Connect account, or add the Heroku Connect addon to your 17 | Heroku app. 18 | 19 | 2. Go through the Heroku Connect setup process, and map your Account and Contact 20 | objects. 21 | 22 | 3. If you want database changes to be synced to Salesforce, enable "Read/Write" 23 | mode on your Heroku Connect account. 24 | 25 | 4. Get your Heroku Connect database credentials and schema name. Set the 26 | `HEROKUCONNECT_URL` and `HEROKUCONNNECT_SCHEMA` variables 27 | in your environment. If you are deploying to heroku, set those values as Config Vars. 28 | 29 | 5. Run the rails console and use the Account or Contact activerecord models 30 | to access your data. Or run the Rails server and access http://localhost:3000 31 | 32 | == Running the app 33 | 34 | Run the Rails server with `rails server` or deploy to Heroku. 35 | 36 | Access the home page, then click the _Sign Up_ link. Enter your email and password. 37 | Now you will be logged in and can access the *Accounts* and *Contacts* pages. 38 | 39 | == Accessing your Salesforce data 40 | 41 | This sample app provides a re-usable ActiveRecord base class called _SalesforceModel_. 42 | This abstract base class will connect to the database specified in the Heroku Connect_URL 43 | environment variable. Any ActiveRecord models to access the Heroku Connect database 44 | should inherit from this class. 45 | 46 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Cloudconnectdemo::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Log error messages when you accidentally call methods on nil. 10 | config.whiny_nils = true 11 | 12 | # Show full error reports and disable caching 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger 20 | config.active_support.deprecation = :log 21 | 22 | # Only use best-standards-support built into browsers 23 | config.action_dispatch.best_standards_support = :builtin 24 | 25 | # Raise exception on mass assignment protection for Active Record models 26 | config.active_record.mass_assignment_sanitizer = :strict 27 | 28 | # Log the query plan for queries taking more than this (works 29 | # with SQLite, MySQL, and PostgreSQL) 30 | config.active_record.auto_explain_threshold_in_seconds = 0.5 31 | 32 | # Do not compress assets 33 | config.assets.compress = false 34 | 35 | # Expands the lines which load the assets 36 | config.assets.debug = true 37 | 38 | config.action_mailer.default_url_options = {:host => "localhost:3000"} 39 | config.action_mailer.smtp_settings = { 40 | address: 'email-smtp.us-east-1.amazonaws.com', 41 | port: 587, 42 | domain: 'cloudconnect.com', 43 | user_name: 'AKIAI23IM4PCXOQW5DJA', 44 | password: 'App5fgsOCorJ9UhJI/rKl2aD4VD3a4+D6KnvOVO0tLEV', 45 | authentication: 'plain', 46 | enable_starttls_auto: true 47 | } 48 | end 49 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Cloudconnectdemo::Application.routes.draw do 2 | devise_for :rails_users 3 | 4 | # The priority is based upon order of creation: 5 | # first created -> highest priority. 6 | 7 | root :to => 'salesforce#accounts' 8 | match '/accounts' => 'salesforce#accounts' 9 | match '/account/:id' => 'salesforce#account' 10 | match '/contacts' => 'salesforce#contacts' 11 | 12 | # Sample of regular route: 13 | # match 'products/:id' => 'catalog#view' 14 | # Keep in mind you can assign values other than :controller and :action 15 | 16 | # Sample of named route: 17 | # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase 18 | # This route can be invoked with purchase_url(:id => product.id) 19 | 20 | # Sample resource route (maps HTTP verbs to controller actions automatically): 21 | # resources :products 22 | 23 | # Sample resource route with options: 24 | # resources :products do 25 | # member do 26 | # get 'short' 27 | # post 'toggle' 28 | # end 29 | # 30 | # collection do 31 | # get 'sold' 32 | # end 33 | # end 34 | 35 | # Sample resource route with sub-resources: 36 | # resources :products do 37 | # resources :comments, :sales 38 | # resource :seller 39 | # end 40 | 41 | # Sample resource route with more complex sub-resources 42 | # resources :products do 43 | # resources :comments 44 | # resources :sales do 45 | # get 'recent', :on => :collection 46 | # end 47 | # end 48 | 49 | # Sample resource route within a namespace: 50 | # namespace :admin do 51 | # # Directs /admin/products/* to Admin::ProductsController 52 | # # (app/controllers/admin/products_controller.rb) 53 | # resources :products 54 | # end 55 | 56 | # You can have the root of your site routed with "root" 57 | # just remember to delete public/index.html. 58 | # root :to => 'welcome#index' 59 | 60 | # See how all your routes lay out with "rake routes" 61 | 62 | # This is a legacy wild controller route that's not recommended for RESTful applications. 63 | # Note: This route will make all actions in every controller accessible via GET requests. 64 | # match ':controller(/:action(/:id))(.:format)' 65 | end 66 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Cloudconnectdemo::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb 3 | config.action_mailer.default_url_options = {:host => "localhost:3000"} 4 | 5 | # Code is not reloaded between requests 6 | config.cache_classes = true 7 | 8 | # Full error reports are disabled and caching is turned on 9 | config.consider_all_requests_local = false 10 | config.action_controller.perform_caching = true 11 | 12 | # Disable Rails's static asset server (Apache or nginx will already do this) 13 | config.serve_static_assets = false 14 | 15 | # Compress JavaScripts and CSS 16 | config.assets.compress = true 17 | 18 | # Don't fallback to assets pipeline if a precompiled asset is missed 19 | config.assets.compile = false 20 | 21 | # Generate digests for assets URLs 22 | config.assets.digest = true 23 | 24 | # Defaults to nil and saved in location specified by config.assets.prefix 25 | # config.assets.manifest = YOUR_PATH 26 | 27 | # Specifies the header that your server uses for sending files 28 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 29 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 30 | 31 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 32 | # config.force_ssl = true 33 | 34 | # See everything in the log (default is :info) 35 | # config.log_level = :debug 36 | 37 | # Prepend all log lines with the following tags 38 | # config.log_tags = [ :subdomain, :uuid ] 39 | 40 | # Use a different logger for distributed setups 41 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 42 | 43 | # Use a different cache store in production 44 | # config.cache_store = :mem_cache_store 45 | 46 | # Enable serving of images, stylesheets, and JavaScripts from an asset server 47 | # config.action_controller.asset_host = "http://assets.example.com" 48 | 49 | # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) 50 | # config.assets.precompile += %w( search.js ) 51 | 52 | # Disable delivery errors, bad email addresses will be ignored 53 | # config.action_mailer.raise_delivery_errors = false 54 | 55 | # Enable threaded mode 56 | # config.threadsafe! 57 | 58 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 59 | # the I18n.default_locale when a translation can not be found) 60 | config.i18n.fallbacks = true 61 | 62 | # Send deprecation notices to registered listeners 63 | config.active_support.deprecation = :notify 64 | 65 | # Log the query plan for queries taking more than this (works 66 | # with SQLite, MySQL, and PostgreSQL) 67 | # config.active_record.auto_explain_threshold_in_seconds = 0.5 68 | end 69 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actionmailer (3.2.13) 5 | actionpack (= 3.2.13) 6 | mail (~> 2.5.3) 7 | actionpack (3.2.13) 8 | activemodel (= 3.2.13) 9 | activesupport (= 3.2.13) 10 | builder (~> 3.0.0) 11 | erubis (~> 2.7.0) 12 | journey (~> 1.0.4) 13 | rack (~> 1.4.5) 14 | rack-cache (~> 1.2) 15 | rack-test (~> 0.6.1) 16 | sprockets (~> 2.2.1) 17 | activemodel (3.2.13) 18 | activesupport (= 3.2.13) 19 | builder (~> 3.0.0) 20 | activerecord (3.2.13) 21 | activemodel (= 3.2.13) 22 | activesupport (= 3.2.13) 23 | arel (~> 3.0.2) 24 | tzinfo (~> 0.3.29) 25 | activeresource (3.2.13) 26 | activemodel (= 3.2.13) 27 | activesupport (= 3.2.13) 28 | activesupport (3.2.13) 29 | i18n (= 0.6.1) 30 | multi_json (~> 1.0) 31 | arel (3.0.2) 32 | atomic (1.1.14) 33 | bcrypt-ruby (3.1.2) 34 | builder (3.0.4) 35 | devise (3.1.0) 36 | bcrypt-ruby (~> 3.0) 37 | orm_adapter (~> 0.1) 38 | railties (>= 3.2.6, < 5) 39 | thread_safe (~> 0.1) 40 | warden (~> 1.2.3) 41 | erubis (2.7.0) 42 | execjs (2.0.1) 43 | hike (1.2.3) 44 | i18n (0.6.1) 45 | journey (1.0.4) 46 | jquery-rails (3.0.4) 47 | railties (>= 3.0, < 5.0) 48 | thor (>= 0.14, < 2.0) 49 | json (1.8.0) 50 | mail (2.5.4) 51 | mime-types (~> 1.16) 52 | treetop (~> 1.4.8) 53 | mime-types (1.24) 54 | multi_json (1.7.9) 55 | orm_adapter (0.4.0) 56 | pg (0.16.0) 57 | polyglot (0.3.3) 58 | rack (1.4.5) 59 | rack-cache (1.2) 60 | rack (>= 0.4) 61 | rack-ssl (1.3.3) 62 | rack 63 | rack-test (0.6.2) 64 | rack (>= 1.0) 65 | rails (3.2.13) 66 | actionmailer (= 3.2.13) 67 | actionpack (= 3.2.13) 68 | activerecord (= 3.2.13) 69 | activeresource (= 3.2.13) 70 | activesupport (= 3.2.13) 71 | bundler (~> 1.0) 72 | railties (= 3.2.13) 73 | railties (3.2.13) 74 | actionpack (= 3.2.13) 75 | activesupport (= 3.2.13) 76 | rack-ssl (~> 1.3.2) 77 | rake (>= 0.8.7) 78 | rdoc (~> 3.4) 79 | thor (>= 0.14.6, < 2.0) 80 | rake (10.1.0) 81 | rdoc (3.12.2) 82 | json (~> 1.4) 83 | sass (3.2.10) 84 | sass-rails (3.2.6) 85 | railties (~> 3.2.0) 86 | sass (>= 3.1.10) 87 | tilt (~> 1.3) 88 | sprockets (2.2.2) 89 | hike (~> 1.2) 90 | multi_json (~> 1.0) 91 | rack (~> 1.0) 92 | tilt (~> 1.1, != 1.3.0) 93 | thor (0.18.1) 94 | thread_safe (0.1.3) 95 | atomic 96 | tilt (1.4.1) 97 | treetop (1.4.15) 98 | polyglot 99 | polyglot (>= 0.3.1) 100 | tzinfo (0.3.37) 101 | uglifier (2.2.1) 102 | execjs (>= 0.3.0) 103 | multi_json (~> 1.0, >= 1.0.2) 104 | warden (1.2.3) 105 | rack (>= 1.0) 106 | 107 | PLATFORMS 108 | ruby 109 | 110 | DEPENDENCIES 111 | devise 112 | jquery-rails 113 | pg 114 | rails (= 3.2.13) 115 | sass-rails (~> 3.2.3) 116 | uglifier (>= 1.0.3) 117 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | # Pick the frameworks you want: 4 | require "active_record/railtie" 5 | require "action_controller/railtie" 6 | require "action_mailer/railtie" 7 | require "active_resource/railtie" 8 | require "sprockets/railtie" 9 | # require "rails/test_unit/railtie" 10 | 11 | if defined?(Bundler) 12 | # If you precompile assets before deploying to production, use this line 13 | Bundler.require(*Rails.groups(:assets => %w(development test))) 14 | # If you want your assets lazily compiled in production, use this line 15 | # Bundler.require(:default, :assets, Rails.env) 16 | end 17 | 18 | module Cloudconnectdemo 19 | class Application < Rails::Application 20 | # Settings in config/environments/* take precedence over those specified here. 21 | # Application configuration should go into files in config/initializers 22 | # -- all .rb files in that directory are automatically loaded. 23 | 24 | # Custom directories with classes and modules you want to be autoloadable. 25 | # config.autoload_paths += %W(#{config.root}/extras) 26 | 27 | # Only load the plugins named here, in the order given (default is alphabetical). 28 | # :all can be used as a placeholder for all plugins not explicitly named. 29 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 30 | 31 | # Activate observers that should always be running. 32 | # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 33 | 34 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 35 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 36 | # config.time_zone = 'Central Time (US & Canada)' 37 | 38 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 39 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 40 | # config.i18n.default_locale = :de 41 | 42 | # Configure the default encoding used in templates for Ruby 1.9. 43 | config.encoding = "utf-8" 44 | 45 | # Configure sensitive parameters which will be filtered from the log file. 46 | config.filter_parameters += [:password] 47 | 48 | # Enable escaping HTML in JSON. 49 | config.active_support.escape_html_entities_in_json = true 50 | 51 | # Use SQL instead of Active Record's schema dumper when creating the database. 52 | # This is necessary if your schema can't be completely dumped by the schema dumper, 53 | # like if you have constraints or database-specific column types 54 | # config.active_record.schema_format = :sql 55 | 56 | # Enforce whitelist mode for mass assignment. 57 | # This will create an empty whitelist of attributes available for mass-assignment for all models 58 | # in your app. As such, your models will need to explicitly whitelist or blacklist accessible 59 | # parameters by using an attr_accessible or attr_protected declaration. 60 | config.active_record.whitelist_attributes = true 61 | 62 | # Enable the asset pipeline 63 | config.assets.enabled = true 64 | config.assets.initialize_on_precompile = false 65 | 66 | # Version of your assets, change this if you want to expire all your assets 67 | config.assets.version = '1.0' 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /config/locales/devise.en.yml: -------------------------------------------------------------------------------- 1 | # Additional translations at https://github.com/plataformatec/devise/wiki/I18n 2 | 3 | en: 4 | devise: 5 | confirmations: 6 | confirmed: "Your account was successfully confirmed. Please sign in." 7 | confirmed_and_signed_in: "Your account was successfully confirmed. You are now signed in." 8 | send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes." 9 | send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes." 10 | failure: 11 | already_authenticated: "You are already signed in." 12 | inactive: "Your account is not activated yet." 13 | invalid: "Invalid email or password." 14 | invalid_token: "Invalid authentication token." 15 | locked: "Your account is locked." 16 | not_found_in_database: "Invalid email or password." 17 | timeout: "Your session expired. Please sign in again to continue." 18 | unauthenticated: "You need to sign in or sign up before continuing." 19 | unconfirmed: "You have to confirm your account before continuing." 20 | mailer: 21 | confirmation_instructions: 22 | subject: "Confirmation instructions" 23 | reset_password_instructions: 24 | subject: "Reset password instructions" 25 | unlock_instructions: 26 | subject: "Unlock Instructions" 27 | omniauth_callbacks: 28 | failure: "Could not authenticate you from %{kind} because \"%{reason}\"." 29 | success: "Successfully authenticated from %{kind} account." 30 | passwords: 31 | no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." 32 | send_instructions: "You will receive an email with instructions about how to reset your password in a few minutes." 33 | send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." 34 | updated: "Your password was changed successfully. You are now signed in." 35 | updated_not_active: "Your password was changed successfully." 36 | registrations: 37 | destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon." 38 | signed_up: "Welcome! You have signed up successfully." 39 | signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." 40 | signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." 41 | signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account." 42 | update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address." 43 | updated: "You updated your account successfully." 44 | sessions: 45 | signed_in: "Signed in successfully." 46 | signed_out: "Signed out successfully." 47 | unlocks: 48 | send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes." 49 | send_paranoid_instructions: "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes." 50 | unlocked: "Your account has been unlocked successfully. Please sign in to continue." 51 | errors: 52 | messages: 53 | already_confirmed: "was already confirmed, please try signing in" 54 | confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" 55 | expired: "has expired, please request a new one" 56 | not_found: "not found" 57 | not_locked: "was not locked" 58 | not_saved: 59 | one: "1 error prohibited this %{resource} from being saved:" 60 | other: "%{count} errors prohibited this %{resource} from being saved:" 61 | -------------------------------------------------------------------------------- /config/initializers/devise.rb: -------------------------------------------------------------------------------- 1 | # Use this hook to configure devise mailer, warden hooks and so forth. 2 | # Many of these configuration options can be set straight in your model. 3 | Devise.setup do |config| 4 | # The secret key used by Devise. Devise uses this key to generate 5 | # random tokens. Changing this key will render invalid all existing 6 | # confirmation, reset password and unlock tokens in the database. 7 | config.secret_key = 'd319a88fa11147273383034ddad8f9f519e56ff182a357efbe395bc852e39f37b2690962abadd9bd1eb68d2fa3771a5da33df54862daac603c1d8cba7182b6d3' 8 | 9 | # ==> Mailer Configuration 10 | # Configure the e-mail address which will be shown in Devise::Mailer, 11 | # note that it will be overwritten if you use your own mailer class 12 | # with default "from" parameter. 13 | config.mailer_sender = 'scottpersinger@gmail.com' 14 | 15 | # Configure the class responsible to send e-mails. 16 | # config.mailer = 'Devise::Mailer' 17 | 18 | # ==> ORM configuration 19 | # Load and configure the ORM. Supports :active_record (default) and 20 | # :mongoid (bson_ext recommended) by default. Other ORMs may be 21 | # available as additional gems. 22 | require 'devise/orm/active_record' 23 | 24 | # ==> Configuration for any authentication mechanism 25 | # Configure which keys are used when authenticating a user. The default is 26 | # just :email. You can configure it to use [:username, :subdomain], so for 27 | # authenticating a user, both parameters are required. Remember that those 28 | # parameters are used only when authenticating and not when retrieving from 29 | # session. If you need permissions, you should implement that in a before filter. 30 | # You can also supply a hash where the value is a boolean determining whether 31 | # or not authentication should be aborted when the value is not present. 32 | config.authentication_keys = [ :email ] 33 | 34 | # Configure parameters from the request object used for authentication. Each entry 35 | # given should be a request method and it will automatically be passed to the 36 | # find_for_authentication method and considered in your model lookup. For instance, 37 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. 38 | # The same considerations mentioned for authentication_keys also apply to request_keys. 39 | # config.request_keys = [] 40 | 41 | # Configure which authentication keys should be case-insensitive. 42 | # These keys will be downcased upon creating or modifying a user and when used 43 | # to authenticate or find a user. Default is :email. 44 | config.case_insensitive_keys = [ :email ] 45 | 46 | # Configure which authentication keys should have whitespace stripped. 47 | # These keys will have whitespace before and after removed upon creating or 48 | # modifying a user and when used to authenticate or find a user. Default is :email. 49 | config.strip_whitespace_keys = [ :email ] 50 | 51 | # Tell if authentication through request.params is enabled. True by default. 52 | # It can be set to an array that will enable params authentication only for the 53 | # given strategies, for example, `config.params_authenticatable = [:database]` will 54 | # enable it only for database (email + password) authentication. 55 | # config.params_authenticatable = true 56 | 57 | # Tell if authentication through HTTP Auth is enabled. False by default. 58 | # It can be set to an array that will enable http authentication only for the 59 | # given strategies, for example, `config.http_authenticatable = [:token]` will 60 | # enable it only for token authentication. The supported strategies are: 61 | # :database = Support basic authentication with authentication key + password 62 | # :token = Support basic authentication with token authentication key 63 | # :token_options = Support token authentication with options as defined in 64 | # http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Token.html 65 | # config.http_authenticatable = false 66 | 67 | # If http headers should be returned for AJAX requests. True by default. 68 | # config.http_authenticatable_on_xhr = true 69 | 70 | # The realm used in Http Basic Authentication. 'Application' by default. 71 | # config.http_authentication_realm = 'Application' 72 | 73 | # It will change confirmation, password recovery and other workflows 74 | # to behave the same regardless if the e-mail provided was right or wrong. 75 | # Does not affect registerable. 76 | # config.paranoid = true 77 | 78 | # By default Devise will store the user in session. You can skip storage for 79 | # :http_auth and :token_auth by adding those symbols to the array below. 80 | # Notice that if you are skipping storage for all authentication paths, you 81 | # may want to disable generating routes to Devise's sessions controller by 82 | # passing :skip => :sessions to `devise_for` in your config/routes.rb 83 | config.skip_session_storage = [:http_auth] 84 | 85 | # By default, Devise cleans up the CSRF token on authentication to 86 | # avoid CSRF token fixation attacks. This means that, when using AJAX 87 | # requests for sign in and sign up, you need to get a new CSRF token 88 | # from the server. You can disable this option at your own risk. 89 | # config.clean_up_csrf_token_on_authentication = true 90 | 91 | # ==> Configuration for :database_authenticatable 92 | # For bcrypt, this is the cost for hashing the password and defaults to 10. If 93 | # using other encryptors, it sets how many times you want the password re-encrypted. 94 | # 95 | # Limiting the stretches to just one in testing will increase the performance of 96 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use 97 | # a value less than 10 in other environments. 98 | config.stretches = Rails.env.test? ? 1 : 10 99 | 100 | # Setup a pepper to generate the encrypted password. 101 | # config.pepper = '323473f66543f1f9238ef93bf0355c4fa8b3202431916c71ffbcdfacd15e613707551d4fba903b2831378f1702f704260de717770b2232bc2ad66fa8d2d81e92' 102 | 103 | # ==> Configuration for :confirmable 104 | # A period that the user is allowed to access the website even without 105 | # confirming his account. For instance, if set to 2.days, the user will be 106 | # able to access the website for two days without confirming his account, 107 | # access will be blocked just in the third day. Default is 0.days, meaning 108 | # the user cannot access the website without confirming his account. 109 | config.allow_unconfirmed_access_for = 0 110 | 111 | # A period that the user is allowed to confirm their account before their 112 | # token becomes invalid. For example, if set to 3.days, the user can confirm 113 | # their account within 3 days after the mail was sent, but on the fourth day 114 | # their account can't be confirmed with the token any more. 115 | # Default is nil, meaning there is no restriction on how long a user can take 116 | # before confirming their account. 117 | # config.confirm_within = 3.days 118 | 119 | # If true, requires any email changes to be confirmed (exactly the same way as 120 | # initial account confirmation) to be applied. Requires additional unconfirmed_email 121 | # db field (see migrations). Until confirmed new email is stored in 122 | # unconfirmed email column, and copied to email column on successful confirmation. 123 | config.reconfirmable = true 124 | 125 | # Defines which key will be used when confirming an account 126 | # config.confirmation_keys = [ :email ] 127 | 128 | # ==> Configuration for :rememberable 129 | # The time the user will be remembered without asking for credentials again. 130 | # config.remember_for = 2.weeks 131 | 132 | # If true, extends the user's remember period when remembered via cookie. 133 | # config.extend_remember_period = false 134 | 135 | # Options to be passed to the created cookie. For instance, you can set 136 | # :secure => true in order to force SSL only cookies. 137 | # config.rememberable_options = {} 138 | 139 | # ==> Configuration for :validatable 140 | # Range for password length. Default is 8..128. 141 | config.password_length = 8..128 142 | 143 | # Email regex used to validate email formats. It simply asserts that 144 | # one (and only one) @ exists in the given string. This is mainly 145 | # to give user feedback and not to assert the e-mail validity. 146 | # config.email_regexp = /\A[^@]+@[^@]+\z/ 147 | 148 | # ==> Configuration for :timeoutable 149 | # The time you want to timeout the user session without activity. After this 150 | # time the user will be asked for credentials again. Default is 30 minutes. 151 | # config.timeout_in = 30.minutes 152 | 153 | # If true, expires auth token on session timeout. 154 | # config.expire_auth_token_on_timeout = false 155 | 156 | # ==> Configuration for :lockable 157 | # Defines which strategy will be used to lock an account. 158 | # :failed_attempts = Locks an account after a number of failed attempts to sign in. 159 | # :none = No lock strategy. You should handle locking by yourself. 160 | # config.lock_strategy = :failed_attempts 161 | 162 | # Defines which key will be used when locking and unlocking an account 163 | # config.unlock_keys = [ :email ] 164 | 165 | # Defines which strategy will be used to unlock an account. 166 | # :email = Sends an unlock link to the user email 167 | # :time = Re-enables login after a certain amount of time (see :unlock_in below) 168 | # :both = Enables both strategies 169 | # :none = No unlock strategy. You should handle unlocking by yourself. 170 | # config.unlock_strategy = :both 171 | 172 | # Number of authentication tries before locking an account if lock_strategy 173 | # is failed attempts. 174 | # config.maximum_attempts = 20 175 | 176 | # Time interval to unlock the account if :time is enabled as unlock_strategy. 177 | # config.unlock_in = 1.hour 178 | 179 | # ==> Configuration for :recoverable 180 | # 181 | # Defines which key will be used when recovering the password for an account 182 | # config.reset_password_keys = [ :email ] 183 | 184 | # Time interval you can reset your password with a reset password key. 185 | # Don't put a too small interval or your users won't have the time to 186 | # change their passwords. 187 | config.reset_password_within = 6.hours 188 | 189 | # ==> Configuration for :encryptable 190 | # Allow you to use another encryption algorithm besides bcrypt (default). You can use 191 | # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, 192 | # :authlogic_sha512 (then you should set stretches above to 20 for default behavior) 193 | # and :restful_authentication_sha1 (then you should set stretches to 10, and copy 194 | # REST_AUTH_SITE_KEY to pepper). 195 | # 196 | # Require the `devise-encryptable` gem when using anything other than bcrypt 197 | # config.encryptor = :sha512 198 | 199 | # ==> Configuration for :token_authenticatable 200 | # Defines name of the authentication token params key 201 | # config.token_authentication_key = :auth_token 202 | 203 | # ==> Scopes configuration 204 | # Turn scoped views on. Before rendering "sessions/new", it will first check for 205 | # "users/sessions/new". It's turned off by default because it's slower if you 206 | # are using only default views. 207 | # config.scoped_views = false 208 | 209 | # Configure the default scope given to Warden. By default it's the first 210 | # devise role declared in your routes (usually :user). 211 | # config.default_scope = :user 212 | 213 | # Set this configuration to false if you want /users/sign_out to sign out 214 | # only the current scope. By default, Devise signs out all scopes. 215 | # config.sign_out_all_scopes = true 216 | 217 | # ==> Navigation configuration 218 | # Lists the formats that should be treated as navigational. Formats like 219 | # :html, should redirect to the sign in page when the user does not have 220 | # access, but formats like :xml or :json, should return 401. 221 | # 222 | # If you have any extra navigational formats, like :iphone or :mobile, you 223 | # should add them to the navigational formats lists. 224 | # 225 | # The "*/*" below is required to match Internet Explorer requests. 226 | # config.navigational_formats = ['*/*', :html] 227 | 228 | # The default HTTP method used to sign out a resource. Default is :delete. 229 | config.sign_out_via = :delete 230 | 231 | # ==> OmniAuth 232 | # Add a new OmniAuth provider. Check the wiki for more information on setting 233 | # up on your models and hooks. 234 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo' 235 | 236 | # ==> Warden configuration 237 | # If you want to use other strategies, that are not supported by Devise, or 238 | # change the failure app, you can configure them inside the config.warden block. 239 | # 240 | # config.warden do |manager| 241 | # manager.intercept_401 = false 242 | # manager.default_strategies(:scope => :user).unshift :some_external_strategy 243 | # end 244 | 245 | # ==> Mountable engine configurations 246 | # When using Devise inside an engine, let's call it `MyEngine`, and this engine 247 | # is mountable, there are some extra configurations to be taken into account. 248 | # The following options are available, assuming the engine is mounted as: 249 | # 250 | # mount MyEngine, at: '/my_engine' 251 | # 252 | # The router that invoked `devise_for`, in the example above, would be: 253 | # config.router_name = :my_engine 254 | # 255 | # When using omniauth, Devise cannot automatically set Omniauth path, 256 | # so you need to do it manually. For the users scope, it would be: 257 | # config.omniauth_path_prefix = '/my_engine/users/auth' 258 | end 259 | --------------------------------------------------------------------------------