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 UserMailer < ActionMailer::Base | |
| default from: 'notify@example.com' | |
| def welcome_email(user) | |
| @user = user | |
| @url = 'https://myapp.herokuapp.com' | |
| mail(to: @user.email, subject: 'Welcome to myapp.') | |
| 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
| module SessionsHelper | |
| def sign_in(user) | |
| remember_token = User.new_remember_token | |
| cookies.permanent[:remember_token] = remember_token | |
| user.update_attribute(:remember_token, User.encrypt(remember_token)) | |
| self.current_user = user | |
| end | |
| def current_user=(user) |
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
| # This file should contain all the record creation needed to seed the database with its default values. | |
| # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). | |
| # | |
| # Examples: | |
| # | |
| # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) | |
| # Mayor.create(name: 'Emanuel', city: cities.first) | |
| Teacher.create(name: 'Albus Dumbledore', | |
| email: 'dumbledore@hogwarts.info', |
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
| # Spec is here: https://gist.github.com/3db3848deae0a3444a03.git | |
| class LegacyCodeMatchesProvinceValidator < ActiveModel::Validator | |
| def validate(record) | |
| valid_matches = [['Damascus & Rif Dimashq', 11], | |
| ['Aleppo', 12], | |
| ['Homs', 13], | |
| ['Hama', 14], | |
| ['Latakia', 15], | |
| ['Deir Al-Zor', 16], |
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
| # Validator is here: https://gist.github.com/adc8cb0de0c6fa12dfb1.git | |
| require 'rails_helper' | |
| describe LegacyCodeMatchesProvinceValidator do | |
| let(:test_class) do | |
| Class.new do | |
| include ActiveModel::Validations | |
| attr_accessor :name |
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 Province < ActiveRecord::Base | |
| validates :name, presence: true, uniqueness: true | |
| validates :code, presence: true, uniqueness: true, inclusion: { in: 10..99 } | |
| end | |
| class Partner < ActiveRecord::Base | |
| validates :name, presence: true, uniqueness: true | |
| validates :province, presence: true | |
| 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
| # config/routes.rb | |
| post '/admin/sponsors/:sponsor_id/sponsorships/:orphan_id', | |
| to: 'admin/sponsorships#create', | |
| as: :admin_sponsorship_create | |
| delete '/admin/sponsors/:sponsor_id/sponsorships/:orphan_id', | |
| to: 'admin/sponsorships#destroy', | |
| as: :admin_sponsorship_destroy | |
| # app/admin/sponsorship.rb |
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
| it 'adds up fast' do | |
| puts "initial: #{Province.all.count}" # 0 | |
| create(:address) | |
| puts "address: #{Province.all.count}" # 1 - belongs_to :province | |
| create(:branch) | |
| puts "branch: #{Province.all.count}" # 1 | |
| create(:organization) | |
| puts "organization: #{Province.all.count}" # 1 | |
| create :orphan_sponsorship_status | |
| puts "orphan_sponsorship_status: #{Province.all.count}" # 1 |
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
| # Solution 1 | |
| class Partner < ActiveRecord::Base | |
| belongs_to :province | |
| has_many :orphan_lists | |
| delegate :code, to: :province, prefix: true | |
| end | |
| class Orphan < ActiveRecord::Base |
OlderNewer