30 | ```
31 |
32 | The category links in the sidebar_menu partial are something like the following:
33 | ```erb
34 | <%= link_to cat.name, fetch_items_path(:cat_id => cat.id), :remote => true %>
35 | ```
36 | fetch_items_path is the route that leads to our custom javascript method, which will be described next.
37 |
38 | config/routes.rb
39 | ```ruby
40 | get "/fetch_items" => 'items#from_category', as: 'fetch_items'
41 | ```
42 |
43 | For more info on how to build custom routes, check Rails amazing documentation.
44 |
45 | **The :remote => true is the most important part here, it allows the whole Ajax business in the first place.**
46 |
47 | The item_grid partial looks like:
48 | ```erb
49 |
54 | ```
55 | The subpartial items_list just renders a list of div boxes to show our Item instances.
56 | ```erb
57 | <% items.each do |item| %>
58 |
59 | ...
60 |
61 | <% end %>
62 | ```
63 | Now we need the method that will do the AJAX magic. For simplicity you could have something like this:
64 |
65 | items_controller.rb
66 | ```ruby
67 | def from_category
68 | @selected = Item.where(:category_id => params[:cat_id])
69 | respond_to do |format|
70 | format.js
71 | end
72 | end
73 | ```
74 | Notice the type of format, there's no html view because we don't need it.
75 | We're going through JS. Therefore, we need to create a javascript file,
76 | which will repopulate the div in the second column.
77 |
78 | //views/items/from_category.js.erb
79 | ```js
80 | $("#items_grid").html("<%= escape_javascript(render partial: 'items_list', locals: { items: @selected } ) %>");
81 | ```
82 | Let's look at this line with care. I'm rendering the same partial I was rendering in items#index,
83 | and the local variable for the partial is now the array of Item instances that match a given category.
84 | The difference is that I'm doing this through AJAX, so there's no need to reload the entire page.
85 |
--------------------------------------------------------------------------------
/agile.md:
--------------------------------------------------------------------------------
1 | ### Notes from Practices of an Agile Developer
2 | * Tackle small problems while they are still small
3 | * Explore the unknown before you invest too much in it
4 | * In an Agile team the primary focus should be Outcomes. Leave ego's at the
5 | door
6 | * Outcome is what's important, not the credit, blame, or anything else
7 | * If you arn't making any mistakes youre probably not trying hard enough
8 | * There may not be a best answer, just a more suitable solution
9 | * Don't start rejecting and rewriting simply because you can't understand it
10 | right away. That's not courage; that's impatience.
11 | * A well educated team is a better team. Figure out how to level up and
12 | elevate the people around you.
13 | * It's important to have iteration schedules so you get in a state of flow with
14 | pushing features.
15 | * When doing upfront design work: discuss possible class designs in terms of
16 | responsibilities. What are classes supposed to do? What other objects will
17 | work with it to get the job done?
18 | * A good design is accurate, but not precise.
19 |
20 |
--------------------------------------------------------------------------------
/animations.md:
--------------------------------------------------------------------------------
1 | # Adding Animations to Rails
2 |
3 | 1. Download animate.css
4 | 2. Put in vendor/assets/stylsheets
5 | 3. In application.scss add this line: `*= require animate`
6 | 4. Set up some JS to add animation classes when I want them.
7 |
8 | Alternatively, you can use [this gem which does those things for
9 | you](https://github.com/camelmasa/animate-rails)
10 |
11 |
12 | When adding transitions/transforms to my css here are some neat tricks:
13 | ```css
14 | .profile-icon {
15 | transition: all .2s ease-in-out;
16 | &:hover {
17 | transform: scale(1.3);
18 | }
19 | }
20 |
21 | .fa-heart.profile-icon:hover {
22 | color: #8A0707;
23 | }
24 |
25 | .fa-bar-chart.profile-icon:hover {
26 | color: #0B486B;
27 | }
28 |
29 | .fa-comments-o.profile-icon:hover {
30 | color: #3B8686;
31 | }
32 | ```
33 |
--------------------------------------------------------------------------------
/anti_patterns.md:
--------------------------------------------------------------------------------
1 | ### Rails Antipatterns
2 |
3 | When you create scopes (which are really class methods) in a model the return
4 | value will be a AR proxy object that responds to the normal interface for AR.
5 | One thing you can do to refactor fat models is make a bunch of scopes and then
6 | class methods using those scopes in order to increase readability and only have
7 | 1 long SQL statement to the DB.
8 |
9 | ### Rendering Partials - What Rails does behind the scenes
10 |
11 | ```ruby
12 |
13 | <% @posts.each do |post|
14 |
<%= post.title %>
15 |
<%= post.body %>
16 | <% end %>
17 | ```
18 |
19 | Can then become:
20 |
21 | ```ruby
22 |
23 | <% @posts.each do |post|
24 | <%= render partial: 'post', object: :post %>
25 | <% end %>
26 |
27 |
28 |
51 |
52 | ```
53 |
54 | ## Rails Composition
55 |
56 | When models start getting bigger its important to follow SRP and maintain that
57 | each class truly only has one purpose.
58 |
59 | For example imagine we have an Order class that has a bunch of little helper
60 | converter methods like this:
61 |
62 | ```ruby
63 | class Order < ActiveRecord::Base
64 |
65 | def to_xml
66 | ...
67 | end
68 |
69 | def to_json
70 | ...
71 | end
72 |
73 | def to_csv
74 | ...
75 | end
76 |
77 | def to_pdf
78 | ...
79 | end
80 | end
81 | ```
82 |
83 | We could refactor this so Order's have an OrderConverter that maintains the
84 | responsibility of all those smaller helper methods.
85 |
86 | ```ruby
87 | class Order < ActiveRecord::Base
88 | def converter
89 | OrderConverter.new(self)
90 | end
91 | end
92 |
93 | class OrderConverter
94 | attr_reader :order
95 | def initialize(order)
96 | @order = order
97 | end
98 |
99 | def to_xml
100 | ...
101 | end
102 |
103 | def to_json
104 | ...
105 | end
106 |
107 | def to_csv
108 | ...
109 | end
110 |
111 | def to_pdf
112 | ...
113 | end
114 | end
115 | ```
116 |
117 | Now we could call something like `@order.converter.to_pdf` however this is now
118 | breaking the Law of Demeter.
119 |
120 |
121 | Thats nice, but we can take it one step further and allow the Order instances to
122 | delegate those helper method calls directly to their new _composed_ object.
123 |
124 | To fix the Law of Demeter we can use Rails delegation.
125 |
126 | ```ruby
127 | class Order < ActiveRecord::Base
128 | delegate :to_xml, :to_json, :to_csv, :to_pdf, to: :converter
129 | def converter
130 | OrderConverter.new(self)
131 | end
132 | end
133 | ```
134 |
--------------------------------------------------------------------------------
/asset_pipeline.md:
--------------------------------------------------------------------------------
1 | ## Debugging Asset Pipeline
2 |
3 | * Check to see whether or not there are assets precompiled already, if so you
4 | probably need to delete those so it will re-compile them.
5 | * When using sprockets check for require_tree, it will make it so all the css
6 | files get included in a random order which might create issues.
7 | * Deploying to Heroku, check to see when you deploy the asset precompilation
8 | process occurs, if not, check your public/assets folder.
9 |
10 |
11 | ### Rails Asset Pipeline Clinic
12 |
13 | **Assets:** JavaScript, CSS, and other static files we need to properly render
14 | our pages.
15 |
16 | Solves:
17 | * Allows you to nest JS and CSS files in subdirectories
18 | * No longer need to specify the exact order to include files for third party
19 | libraries like Bootstrap or Foundation
20 | * Compresses all our assets so they get served to the browser faster
21 | * Consolidate CSS and JS files into one file so there are less HTTP requests
22 | made by the browser, improving page load speed.
23 | * Allow us to use preprocessors like Sass or Coffee Script.
24 | * Enables caching to further increase page speeds and will re cache assets when
25 | changes are made.
26 |
27 |
28 | #### Three Places To Store Assets:
29 |
30 | app/assets - file specific to current project
31 | lib/assets - files for internal libraries
32 | vendor/assets - files for external libraries
33 |
34 | #### Manifest Files
35 |
36 | app/assets/javascripts/application.js
37 | app/assets/stylesheets/application.css
38 |
39 | The manifest files specify where to find other files to load in and in which
40 | order to load them.
41 |
42 | In order to add to manifest you need there to be a comment in the beginning of
43 | the line and an equals sign.
44 |
45 | ```javascript
46 | //= require foo # single line comment
47 |
48 | /*
49 | *
50 | *
51 | *= require foo # multi line comment
52 | */
53 | ```
54 |
55 | #### Directive In Manifest File
56 |
57 | = require_self: Inserts content of the file itself (after directives).
58 | = require_directory: Loads all files of the same format in the specified
59 | directory in an alphabetical order.
60 | = require_tree: Just like require_directory but it also recursively requires all
61 | files in subdirectories.
62 |
63 | **Note**: Directives are loaded in the order they appear unless you use
64 | require_tree in which case there is no guarantee of the order in which the files
65 | will be included
66 |
67 | #### Search Pathes
68 |
69 | Can be edited with ``config.assets.paths << Rails.root.join('app', 'flash',
70 | 'assets')``
71 |
72 | All standard places are added in search paths. To add fonts you could:
73 | ``app/assets/fonts`` folder since it's under the ``app/assets`` it will be
74 | included. Or you can target files in subdirectories by using a relative path:
75 |
76 | ```ruby
77 | // This will load the app/assets/javascripts/library/foo.js
78 | //= require 'library/foo'
79 | ```
80 |
81 | **Note**: You could put CSS files in JS and JS in CSS folder and everything
82 | would work fine, people would just be annoyed at you.
83 |
84 | #### File Extensions
85 |
86 | Get compiled in the order they are given:
87 | ``products.css.sass.erb`` will run the file through the ERb engine, then sass,
88 | then deliver a css file.
89 |
90 | #### Helpers
91 |
92 | `` <%= stylesheet_link_tag "application" %>``
93 | `` <%= javascript_include_tag "application" %>``
94 |
95 | You can pass in different manifest files other than application to these helpers
96 |
97 | ``image_tag`` knows to search in /app/assets/images
98 |
99 | Sass Helper:
100 | ```ruby
101 | header {
102 | background-image: image-url('header-photo.png')
103 | }
104 | ```
105 |
106 |
--------------------------------------------------------------------------------
/bourbon.md:
--------------------------------------------------------------------------------
1 | ## Getting Bourbon Set Up in Rails
2 |
3 | Add gems to gemfile:
4 | ```ruby
5 | # gemfile
6 |
7 | gem 'bourbon'
8 | gem 'neat'
9 | gem 'refills'
10 | ```
11 |
12 | Change application.css to application.scss:
13 |
14 | ```ruby
15 | /*
16 | * This is a manifest file that'll be compiled into application.css, which will include all the files
17 | * listed below.
18 | *
19 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
20 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
21 | *
22 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the
23 | * compiled file so the styles you add here take precedence over styles defined in any styles
24 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
25 | * file per style scope.
26 | *
27 | *= require foundation_and_overrides
28 | */
29 |
30 | @import 'bourbon';
31 | @import 'neat';
32 | ```
33 |
34 | Remove all the sprockets and import the new sass libraries.
35 |
36 | This example is also using foundation along with Bourbon because it was required
37 | for the app that was being built. In general you can remove the foundation
38 | overrides as well since they shouldn't be needed if you use Neat for the grid.
39 |
40 |
41 |
--------------------------------------------------------------------------------
/confident_ruby.md:
--------------------------------------------------------------------------------
1 | There are implicit and explicit type conversions. When crafting methods if you
2 | need to type check and be confident you are getting the type you are expecting
3 | to use then implement: ``to_str``, ``to_int``, or ``to_a``.
4 |
5 | Using the built in conversion functions: Array(), Integer(), etc. will do
6 | everything possible to convert an object into what you want, it will also supply
7 | stricter qualifications than the tradition .to_s methods. See page 63 for
8 | examples on how to use them.
9 |
10 |
11 |
--------------------------------------------------------------------------------
/cool_gems.md:
--------------------------------------------------------------------------------
1 | ## Cool Gems w/ Descriptions:
2 |
3 | #### Devise:
4 | * user authentication.
5 |
6 | #### Ledermann-rails-settings
7 | Ruby gem to handle settings for ActiveRecord instances by storing them as serialized Hash in a separate database table. Namespaces and defaults included.
8 |
--------------------------------------------------------------------------------
/email.md:
--------------------------------------------------------------------------------
1 | ## Using Email with Rails
2 |
3 | In order to get Mandrill configured properly.. follow this format:
4 |
5 | ```ruby
6 | # production.rb, test.rb, development.rb or application.rb
7 |
8 | YourApp::Application.configure do
9 | config.action_mailer.smtp_settings = {
10 | :address => "smtp.mandrillapp.com",
11 | :port => 25, # ports 587 and 2525 are also supported with STARTTLS
12 | :enable_starttls_auto => true, # detects and uses STARTTLS
13 | :user_name => "MANDRILL_USERNAME",
14 | :password => "MANDRILL_PASSWORD", # SMTP password is any valid API key
15 | :authentication => 'login', # Mandrill supports 'plain' or 'login'
16 | :domain => 'yourdomain.com', # your domain to identify your server when connecting
17 | }
18 |
19 | # …
20 | end
21 | ```
22 |
23 | **Note** By default Heroku set up the configuration variables for Mandrill.
24 | When I was trying to get it to work I didn't realize that my environment
25 | variables were named differently from Mandrills. MAKE SURE TO DOUBLE CHECK YOUR
26 | CALLS TO ENV IN RAILS APP MATCH THE ENVIRONMENT VARIABLE NAMES ON HEROKU!!!
27 |
--------------------------------------------------------------------------------
/flash_card_code.rb:
--------------------------------------------------------------------------------
1 | # Imagine were in users/index.html.haml
2 |
3 | - @post.users.where("age > 23").each do |person|
4 | = person.name
5 |
6 |
7 | # How to put Sinatra app into a Rails app
8 |
9 | class HelloApp < Sinatra::Base
10 | get '/' do
11 | "Hello World!"
12 | end
13 | end
14 |
15 | Rails.application.routes.draw do
16 | mount HelloApp, at: '/hello'
17 | end
18 |
19 | auction = Auction.find(params[:auction_id])
20 | bid = auction.bids.find(params[:id])
21 |
22 | # Making a good looking update
23 | class ProjectController < ApplicationController
24 | def update
25 | project = Project.find(params[:id])
26 | if project.update(params[:project])
27 | redirect_to project
28 | else
29 | render 'edit'
30 | end
31 | end
32 | end
33 |
34 |
--------------------------------------------------------------------------------
/flow_dock.md:
--------------------------------------------------------------------------------
1 | ## Integrating Flowdock Into Rails
2 |
3 | Add flowdock gem and dotenv-rails to Gemfile:
4 | ```
5 | gem "flowdock"
6 |
7 | group :development, :test do
8 | gem "dotenv-rails"
9 | end
10 | ```
11 |
12 | Then add the specific flow token in .env file:
13 |
14 | ```ruby
15 | # .env file
16 | FLOWDOCK_TEST_TOKEN=
17 | ```
18 |
19 | This implementation is for sending flows to the chat. After making this we can
20 | create specific notification types depending on what we want to send. In this
21 | case we wanted to send Announcement objects so we made an announcement
22 | notification.
23 |
24 | ```ruby
25 | module Notifications
26 | class FlowDock
27 | FROM_SOURCE = 'Spencer-Dixon'
28 | EMAIL = 'hello@launchacademy.com'
29 |
30 | def initialize(*args)
31 | @message_args = args.first
32 | @flow = Flowdock::Flow.new(
33 | api_token: token,
34 | source: FROM_SOURCE,
35 | from: {
36 | name: FROM_SOURCE,
37 | address: EMAIL
38 | }
39 | )
40 | end
41 |
42 | def push_to_chat
43 | @flow.push_to_chat(
44 | content: @message_args[:content],
45 | external_user_name: @message_args[:external_user_name]
46 | )
47 | end
48 |
49 | protected
50 | def token
51 | if Rails.env.development? || Rails.env.test?
52 | ENV['FLOWDOCK_TEST_TOKEN']
53 | else
54 | ENV['FLOWDOCK_TOKEN']
55 | end
56 | end
57 | end
58 | end
59 | ```
60 |
61 | Announcement Wrapper:
62 | ```ruby
63 | module Notifications
64 | class AnnouncementNotification
65 |
66 | def initialize(announcement)
67 | @announcement = announcement
68 | end
69 |
70 | def dispatch
71 | Notifications::FlowDock.new(
72 | content: content,
73 | external_user_name: external_user_name
74 | ).push_to_chat
75 | end
76 |
77 | private
78 |
79 | def content
80 | "@everyone, #{@announcement.title}: #{@announcement.description}"
81 | end
82 |
83 | def external_user_name
84 | "Launch-Staff"
85 | end
86 | end
87 | end
88 | ```
89 |
90 | Finally in our controller that creates announcements we can ``#dispatch`` the
91 | announcement on save:
92 |
93 | ```ruby
94 | # announcements_controller.rb
95 | def create
96 | @team = Team.find(params[:team_id])
97 | @announcement = @team.announcements.build(announcement_params)
98 |
99 | if @announcement.save
100 | Notifications::AnnouncementNotification.new(@announcement).dispatch
101 | flash[:info] = "Added announcement."
102 | redirect_to team_announcements_path(@team)
103 | else
104 | flash[:alert] = "Failed to add announcement."
105 | render :index
106 | end
107 | end
108 | ```
109 |
110 | There you have it! One way to integrate Flowdock into Rails.
111 |
112 |
--------------------------------------------------------------------------------
/image_preview.md:
--------------------------------------------------------------------------------
1 | # Image Preview With Carrierwave
2 |
3 | Had a hard time finding good resources for implementing image preview in Rails
4 | with carrierwave. Here's how I did it:
5 |
6 | ```ruby
7 | # ... rest of the form ...
8 |
9 | # Your carrierwave image uploader
10 |
17 |
18 | <%= link_to 'Edit', edit_product_path(@product) %> |
19 | <%= link_to 'Back', products_path %>
20 |
--------------------------------------------------------------------------------
/omni_auth_devise/bin/bundle:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3 | load Gem.bin_path('bundler', 'bundle')
4 |
--------------------------------------------------------------------------------
/omni_auth_devise/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path("../spring", __FILE__)
4 | rescue LoadError
5 | end
6 | APP_PATH = File.expand_path('../../config/application', __FILE__)
7 | require_relative '../config/boot'
8 | require 'rails/commands'
9 |
--------------------------------------------------------------------------------
/omni_auth_devise/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path("../spring", __FILE__)
4 | rescue LoadError
5 | end
6 | require_relative '../config/boot'
7 | require 'rake'
8 | Rake.application.run
9 |
--------------------------------------------------------------------------------
/omni_auth_devise/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require 'pathname'
3 |
4 | # path to your application root.
5 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6 |
7 | Dir.chdir APP_ROOT do
8 | # This script is a starting point to setup your application.
9 | # Add necessary setup steps to this file:
10 |
11 | puts "== Installing dependencies =="
12 | system "gem install bundler --conservative"
13 | system "bundle check || bundle install"
14 |
15 | # puts "\n== Copying sample files =="
16 | # unless File.exist?("config/database.yml")
17 | # system "cp config/database.yml.sample config/database.yml"
18 | # end
19 |
20 | puts "\n== Preparing database =="
21 | system "bin/rake db:setup"
22 |
23 | puts "\n== Removing old logs and tempfiles =="
24 | system "rm -f log/*"
25 | system "rm -rf tmp/cache"
26 |
27 | puts "\n== Restarting application server =="
28 | system "touch tmp/restart.txt"
29 | end
30 |
--------------------------------------------------------------------------------
/omni_auth_devise/bin/spring:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | # This file loads spring without using Bundler, in order to be fast.
4 | # It gets overwritten when you run the `spring binstub` command.
5 |
6 | unless defined?(Spring)
7 | require "rubygems"
8 | require "bundler"
9 |
10 | if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)
11 | Gem.paths = { "GEM_PATH" => [Bundler.bundle_path.to_s, *Gem.path].uniq }
12 | gem "spring", match[1]
13 | require "spring/binstub"
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/omni_auth_devise/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 Rails.application
5 |
--------------------------------------------------------------------------------
/omni_auth_devise/config/application.rb:
--------------------------------------------------------------------------------
1 | require File.expand_path('../boot', __FILE__)
2 |
3 | require "rails"
4 | # Pick the frameworks you want:
5 | require "active_model/railtie"
6 | require "active_job/railtie"
7 | require "active_record/railtie"
8 | require "action_controller/railtie"
9 | require "action_mailer/railtie"
10 | require "action_view/railtie"
11 | require "sprockets/railtie"
12 | # require "rails/test_unit/railtie"
13 |
14 | # Require the gems listed in Gemfile, including any gems
15 | # you've limited to :test, :development, or :production.
16 | Bundler.require(*Rails.groups)
17 |
18 | module OmniAuthDevise
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 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
25 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
26 | # config.time_zone = 'Central Time (US & Canada)'
27 |
28 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
29 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
30 | # config.i18n.default_locale = :de
31 |
32 | # Do not swallow errors in after_commit/after_rollback callbacks.
33 | config.active_record.raise_in_transactional_callbacks = true
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/omni_auth_devise/config/boot.rb:
--------------------------------------------------------------------------------
1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
2 |
3 | require 'bundler/setup' # Set up gems listed in the Gemfile.
4 |
--------------------------------------------------------------------------------
/omni_auth_devise/config/database.yml:
--------------------------------------------------------------------------------
1 | # PostgreSQL. Versions 8.2 and up are supported.
2 | #
3 | # Install the pg driver:
4 | # gem install pg
5 | # On OS X with Homebrew:
6 | # gem install pg -- --with-pg-config=/usr/local/bin/pg_config
7 | # On OS X with MacPorts:
8 | # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
9 | # On Windows:
10 | # gem install pg
11 | # Choose the win32 build.
12 | # Install PostgreSQL and put its /bin directory on your path.
13 | #
14 | # Configure Using Gemfile
15 | # gem 'pg'
16 | #
17 | default: &default
18 | adapter: postgresql
19 | encoding: unicode
20 | # For details on connection pooling, see rails configuration guide
21 | # http://guides.rubyonrails.org/configuring.html#database-pooling
22 | pool: 5
23 |
24 | development:
25 | <<: *default
26 | database: omni_auth_devise_development
27 |
28 | # The specified database role being used to connect to postgres.
29 | # To create additional roles in postgres see `$ createuser --help`.
30 | # When left blank, postgres will use the default role. This is
31 | # the same name as the operating system user that initialized the database.
32 | #username: omni_auth_devise
33 |
34 | # The password associated with the postgres role (username).
35 | #password:
36 |
37 | # Connect on a TCP socket. Omitted by default since the client uses a
38 | # domain socket that doesn't need configuration. Windows does not have
39 | # domain sockets, so uncomment these lines.
40 | #host: localhost
41 |
42 | # The TCP port the server listens on. Defaults to 5432.
43 | # If your server runs on a different port number, change accordingly.
44 | #port: 5432
45 |
46 | # Schema search path. The server defaults to $user,public
47 | #schema_search_path: myapp,sharedapp,public
48 |
49 | # Minimum log levels, in increasing order:
50 | # debug5, debug4, debug3, debug2, debug1,
51 | # log, notice, warning, error, fatal, and panic
52 | # Defaults to warning.
53 | #min_messages: notice
54 |
55 | # Warning: The database defined as "test" will be erased and
56 | # re-generated from your development database when you run "rake".
57 | # Do not set this db to the same as development or production.
58 | test:
59 | <<: *default
60 | database: omni_auth_devise_test
61 |
62 | # As with config/secrets.yml, you never want to store sensitive information,
63 | # like your database password, in your source code. If your source code is
64 | # ever seen by anyone, they now have access to your database.
65 | #
66 | # Instead, provide the password as a unix environment variable when you boot
67 | # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
68 | # for a full rundown on how to provide these environment variables in a
69 | # production deployment.
70 | #
71 | # On Heroku and other platform providers, you may have a full connection URL
72 | # available as an environment variable. For example:
73 | #
74 | # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
75 | #
76 | # You can use this database configuration with:
77 | #
78 | # production:
79 | # url: <%= ENV['DATABASE_URL'] %>
80 | #
81 | production:
82 | <<: *default
83 | database: omni_auth_devise_production
84 | username: omni_auth_devise
85 | password: <%= ENV['OMNI_AUTH_DEVISE_DATABASE_PASSWORD'] %>
86 |
--------------------------------------------------------------------------------
/omni_auth_devise/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the Rails application.
2 | require File.expand_path('../application', __FILE__)
3 |
4 | # Initialize the Rails application.
5 | Rails.application.initialize!
6 |
--------------------------------------------------------------------------------
/omni_auth_devise/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | Rails.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 | # Do not eager load code on boot.
10 | config.eager_load = false
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 | # Raise an error on page load if there are pending migrations.
23 | config.active_record.migration_error = :page_load
24 |
25 | # Debug mode disables concatenation and preprocessing of assets.
26 | # This option may cause significant delays in view rendering with a large
27 | # number of complex assets.
28 | config.assets.debug = true
29 |
30 | # Asset digests allow you to set far-future HTTP expiration dates on all assets,
31 | # yet still be able to expire them through the digest params.
32 | config.assets.digest = true
33 |
34 | # Adds additional error checking when serving assets at runtime.
35 | # Checks for improperly declared sprockets dependencies.
36 | # Raises helpful error messages.
37 | config.assets.raise_runtime_errors = true
38 |
39 | # Raises error for missing translations
40 | # config.action_view.raise_on_missing_translations = true
41 | end
42 |
--------------------------------------------------------------------------------
/omni_auth_devise/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # Code is not reloaded between requests.
5 | config.cache_classes = true
6 |
7 | # Eager load code on boot. This eager loads most of Rails and
8 | # your application in memory, allowing both threaded web servers
9 | # and those relying on copy on write to perform better.
10 | # Rake tasks automatically ignore this option for performance.
11 | config.eager_load = true
12 |
13 | # Full error reports are disabled and caching is turned on.
14 | config.consider_all_requests_local = false
15 | config.action_controller.perform_caching = true
16 |
17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application
18 | # Add `rack-cache` to your Gemfile before enabling this.
19 | # For large-scale production use, consider using a caching reverse proxy like
20 | # NGINX, varnish or squid.
21 | # config.action_dispatch.rack_cache = true
22 |
23 | # Disable serving static files from the `/public` folder by default since
24 | # Apache or NGINX already handles this.
25 | config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
26 |
27 | # Compress JavaScripts and CSS.
28 | config.assets.js_compressor = :uglifier
29 | # config.assets.css_compressor = :sass
30 |
31 | # Do not fallback to assets pipeline if a precompiled asset is missed.
32 | config.assets.compile = false
33 |
34 | # Asset digests allow you to set far-future HTTP expiration dates on all assets,
35 | # yet still be able to expire them through the digest params.
36 | config.assets.digest = true
37 |
38 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
39 |
40 | # Specifies the header that your server uses for sending files.
41 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
42 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
43 |
44 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
45 | # config.force_ssl = true
46 |
47 | # Use the lowest log level to ensure availability of diagnostic information
48 | # when problems arise.
49 | config.log_level = :debug
50 |
51 | # Prepend all log lines with the following tags.
52 | # config.log_tags = [ :subdomain, :uuid ]
53 |
54 | # Use a different logger for distributed setups.
55 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
56 |
57 | # Use a different cache store in production.
58 | # config.cache_store = :mem_cache_store
59 |
60 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
61 | # config.action_controller.asset_host = 'http://assets.example.com'
62 |
63 | # Ignore bad email addresses and do not raise email delivery errors.
64 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
65 | # config.action_mailer.raise_delivery_errors = false
66 |
67 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
68 | # the I18n.default_locale when a translation cannot be found).
69 | config.i18n.fallbacks = true
70 |
71 | # Send deprecation notices to registered listeners.
72 | config.active_support.deprecation = :notify
73 |
74 | # Use default logging formatter so that PID and timestamp are not suppressed.
75 | config.log_formatter = ::Logger::Formatter.new
76 |
77 | # Do not dump schema after migrations.
78 | config.active_record.dump_schema_after_migration = false
79 | end
80 |
--------------------------------------------------------------------------------
/omni_auth_devise/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | Rails.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 | # Do not eager load code on boot. This avoids loading your whole application
11 | # just for the purpose of running a single test. If you are using a tool that
12 | # preloads Rails for running tests, you may have to set it to true.
13 | config.eager_load = false
14 |
15 | # Configure static file server for tests with Cache-Control for performance.
16 | config.serve_static_files = true
17 | config.static_cache_control = 'public, max-age=3600'
18 |
19 | # Show full error reports and disable caching.
20 | config.consider_all_requests_local = true
21 | config.action_controller.perform_caching = false
22 |
23 | # Raise exceptions instead of rendering exception templates.
24 | config.action_dispatch.show_exceptions = false
25 |
26 | # Disable request forgery protection in test environment.
27 | config.action_controller.allow_forgery_protection = false
28 |
29 | # Tell Action Mailer not to deliver emails to the real world.
30 | # The :test delivery method accumulates sent emails in the
31 | # ActionMailer::Base.deliveries array.
32 | config.action_mailer.delivery_method = :test
33 |
34 | # Randomize the order test cases are executed.
35 | config.active_support.test_order = :random
36 |
37 | # Print deprecation notices to the stderr.
38 | config.active_support.deprecation = :stderr
39 |
40 | # Raises error for missing translations
41 | # config.action_view.raise_on_missing_translations = true
42 | end
43 |
--------------------------------------------------------------------------------
/omni_auth_devise/config/initializers/assets.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Version of your assets, change this if you want to expire all your assets.
4 | Rails.application.config.assets.version = '1.0'
5 |
6 | # Add additional assets to the asset load path
7 | # Rails.application.config.assets.paths << Emoji.images_path
8 |
9 | # Precompile additional assets.
10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
11 | # Rails.application.config.assets.precompile += %w( search.js )
12 |
--------------------------------------------------------------------------------
/omni_auth_devise/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 |
--------------------------------------------------------------------------------
/omni_auth_devise/config/initializers/cookies_serializer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Rails.application.config.action_dispatch.cookies_serializer = :json
4 |
--------------------------------------------------------------------------------
/omni_auth_devise/config/initializers/devise.rb:
--------------------------------------------------------------------------------
1 | Devise.setup do |config|
2 | config.mailer_sender = 'mailer@example.com'
3 |
4 | require 'devise/orm/active_record'
5 | config.case_insensitive_keys = [ :email ]
6 | config.strip_whitespace_keys = [ :email ]
7 | config.skip_session_storage = [:http_auth]
8 | config.stretches = Rails.env.test? ? 1 : 10
9 | config.reconfirmable = true
10 | config.expire_all_remember_me_on_sign_out = true
11 | config.password_length = 8..128
12 | config.reset_password_within = 6.hours
13 | config.sign_out_via = :delete
14 |
15 | config.omniauth :github, ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"]
16 | end
17 |
--------------------------------------------------------------------------------
/omni_auth_devise/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Configure sensitive parameters which will be filtered from the log file.
4 | Rails.application.config.filter_parameters += [:password]
5 |
--------------------------------------------------------------------------------
/omni_auth_devise/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. Inflections
4 | # are locale specific, and you may define rules for as many different
5 | # locales as you wish. All of these examples are active by default:
6 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
7 | # inflect.plural /^(ox)$/i, '\1en'
8 | # inflect.singular /^(ox)en/i, '\1'
9 | # inflect.irregular 'person', 'people'
10 | # inflect.uncountable %w( fish sheep )
11 | # end
12 |
13 | # These inflection rules are supported but not enabled by default:
14 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
15 | # inflect.acronym 'RESTful'
16 | # end
17 |
--------------------------------------------------------------------------------
/omni_auth_devise/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 |
--------------------------------------------------------------------------------
/omni_auth_devise/config/initializers/session_store.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Rails.application.config.session_store :cookie_store, key: '_omni_auth_devise_session'
4 |
--------------------------------------------------------------------------------
/omni_auth_devise/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] if respond_to?(:wrap_parameters)
9 | end
10 |
11 | # To enable root element in JSON for ActiveRecord objects.
12 | # ActiveSupport.on_load(:active_record) do
13 | # self.include_root_in_json = true
14 | # end
15 |
--------------------------------------------------------------------------------
/omni_auth_devise/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization
2 | # and are automatically loaded by Rails. If you want to use locales other
3 | # than English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t 'hello'
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t('hello') %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # To learn more, please read the Rails Internationalization guide
20 | # available at http://guides.rubyonrails.org/i18n.html.
21 |
22 | en:
23 | hello: "Hello world"
24 |
--------------------------------------------------------------------------------
/omni_auth_devise/config/routes.rb:
--------------------------------------------------------------------------------
1 | Rails.application.routes.draw do
2 | devise_for :users, :controllers => { :omniauth_callbacks => "callbacks" }
3 | resources :products
4 | root 'products#index'
5 | end
6 |
--------------------------------------------------------------------------------
/omni_auth_devise/config/secrets.yml:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Your secret key is used for verifying the integrity of signed cookies.
4 | # If you change this key, all old signed cookies will become invalid!
5 |
6 | # Make sure the secret is at least 30 characters and all random,
7 | # no regular words or you'll be exposed to dictionary attacks.
8 | # You can use `rake secret` to generate a secure secret key.
9 |
10 | # Make sure the secrets in this file are kept private
11 | # if you're sharing your code publicly.
12 |
13 | development:
14 | secret_key_base: fd8eaaccc0f1ee1cfa546c449e676a515f6e5727e41986b378cc78ed4bcc7381f99853ebf88791cc6270985be79f1b5eee10e69e2390e22a3b8572abbe1e3369
15 |
16 | test:
17 | secret_key_base: 779ae115c8158ea5c60ef1521e146f294bf8ce8e179b4294c79fa0ce9a338a7c0e4ff857265263e2fe762960067d04b7b978a80482524d8bb13d7a8aa6d52876
18 |
19 | # Do not keep production secrets in the repository,
20 | # instead read values from the environment.
21 | production:
22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
23 |
--------------------------------------------------------------------------------
/omni_auth_devise/db/migrate/20150328151012_create_products.rb:
--------------------------------------------------------------------------------
1 | class CreateProducts < ActiveRecord::Migration
2 | def change
3 | create_table :products do |t|
4 | t.string :name
5 | t.integer :price
6 | t.text :description
7 |
8 | t.timestamps null: false
9 | end
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/omni_auth_devise/db/migrate/20150328151138_devise_create_users.rb:
--------------------------------------------------------------------------------
1 | class DeviseCreateUsers < ActiveRecord::Migration
2 | def change
3 | create_table(: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.inet :current_sign_in_ip
20 | t.inet :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 | t.timestamps
35 | end
36 |
37 | add_index :users, :email, unique: true
38 | add_index :users, :reset_password_token, unique: true
39 | # add_index :users, :confirmation_token, unique: true
40 | # add_index :users, :unlock_token, unique: true
41 | end
42 | end
43 |
--------------------------------------------------------------------------------
/omni_auth_devise/db/migrate/20150328151341_add_columns_to_users.rb:
--------------------------------------------------------------------------------
1 | class AddColumnsToUsers < ActiveRecord::Migration
2 | def change
3 | add_column :users, :provider, :string
4 | add_column :users, :uid, :string
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/omni_auth_devise/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 that you check this file into your version control system.
13 |
14 | ActiveRecord::Schema.define(version: 20150328151341) do
15 |
16 | # These are extensions that must be enabled in order to support this database
17 | enable_extension "plpgsql"
18 |
19 | create_table "products", force: :cascade do |t|
20 | t.string "name"
21 | t.integer "price"
22 | t.text "description"
23 | t.datetime "created_at", null: false
24 | t.datetime "updated_at", null: false
25 | end
26 |
27 | create_table "users", force: :cascade do |t|
28 | t.string "email", default: "", null: false
29 | t.string "encrypted_password", default: "", null: false
30 | t.string "reset_password_token"
31 | t.datetime "reset_password_sent_at"
32 | t.datetime "remember_created_at"
33 | t.integer "sign_in_count", default: 0, null: false
34 | t.datetime "current_sign_in_at"
35 | t.datetime "last_sign_in_at"
36 | t.inet "current_sign_in_ip"
37 | t.inet "last_sign_in_ip"
38 | t.datetime "created_at"
39 | t.datetime "updated_at"
40 | t.string "provider"
41 | t.string "uid"
42 | end
43 |
44 | add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
45 | add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
46 |
47 | end
48 |
--------------------------------------------------------------------------------
/omni_auth_devise/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 |
--------------------------------------------------------------------------------
/omni_auth_devise/lib/assets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SpencerCDixon/rails-tricks/dd994681ff33c36a82303a00d2500dbd2a3050a5/omni_auth_devise/lib/assets/.keep
--------------------------------------------------------------------------------
/omni_auth_devise/lib/tasks/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SpencerCDixon/rails-tricks/dd994681ff33c36a82303a00d2500dbd2a3050a5/omni_auth_devise/lib/tasks/.keep
--------------------------------------------------------------------------------
/omni_auth_devise/log/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SpencerCDixon/rails-tricks/dd994681ff33c36a82303a00d2500dbd2a3050a5/omni_auth_devise/log/.keep
--------------------------------------------------------------------------------
/omni_auth_devise/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The page you were looking for doesn't exist.
62 |
You may have mistyped the address or the page may have moved.
63 |
64 |
If you are the application owner check the logs for more information.