This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CreateTeamsUsersWithId < ActiveRecord::Migration | |
| def change | |
| create_table :team_user_tmps do |t| | |
| t.belongs_to :team, :null => false, :index => true | |
| t.belongs_to :user, :null => false, :index => true | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Team < ActiveRecord::Base | |
| has_many :team_users | |
| has_many :users, :through => :team_users | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Team < ActiveRecord::Base | |
| has_and_belongs_to_many :users | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(function() { | |
| var source = new Bloodhound({ | |
| /* create source as usual... */ | |
| }); | |
| source.initialize(); | |
| // Check if the query matches exactly | |
| function noDirectMatch(matches, query) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # require_and_profile.rb | |
| # from http://stackoverflow.com/questions/13065408/how-to-measure-how-much-memory-each-gem-requires-at-initialization | |
| def require_and_profile(gemname = nil) | |
| unless gemname | |
| puts "%-20s: %10s | %10s" % ['gem','increment','total'] | |
| return | |
| end | |
| #puts "Trying #{gemname}" | |
| # This is how to get memory of calling process in OS X, check host OS for variants | |
| memory_usage = `ps -o rss= -p #{Process.pid}`.to_i / 1024.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Book = Struct.new(:title, :year_published) do | |
| def decade_published | |
| year_published - year_published % 10 | |
| end | |
| def to_s | |
| "#{title} (#{year_published})" | |
| end | |
| end | |
| bookshelf = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="signin-container"> | |
| <h2>Sign in with</h2> | |
| <%- if devise_mapping.omniauthable? %> | |
| <ul class="image-list signin-icons"> | |
| <%- resource_class.omniauth_providers.each do |provider| %> | |
| <li><%= link_to omniauth_authorize_path(resource_name, provider), :title => "Sign in with #{provider.to_s.titleize}" do %> | |
| <%= image_tag "oauth_#{provider}.png", :alt => "Sign in with #{provider.to_s.titleize}" %><% end -%> | |
| </li> | |
| <% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <ul class="nav"> | |
| <% if user_signed_in? -%> | |
| <li><%= link_to 'Sign out', destroy_user_session_path, :method => :delete %></li> | |
| <% else -%> | |
| <li><%= link_to 'Sign in', new_user_session_path %></li> | |
| <% end -%> | |
| </ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController | |
| skip_before_action :verify_authenticity_token | |
| def sign_in_with(provider_name) | |
| @user = User.from_omniauth(request.env["omniauth.auth"]) | |
| sign_in_and_redirect @user, :event => :authentication | |
| set_flash_message(:notice, :success, :kind => provider_name) if is_navigational_format? | |
| end | |
| def facebook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Rails.application.routes.draw do | |
| devise_for :users, :controllers => { | |
| :omniauth_callbacks => "users/omniauth_callbacks" | |
| } | |
| devise_scope :user do | |
| get 'sign_in', :to => 'devise/sessions#new', :as => :new_user_session | |
| delete 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_user_session | |
| end | |
| root 'home#index' |