Skip to content

Instantly share code, notes, and snippets.

class AccountsController < ApplicationController
protect_from_forgery except: :webhook
skip_before_action :require_login, only: [:new, :create]
def index
end
def new
@account = Account.new
@account.admin = Employee.new
@sirramongabriel
sirramongabriel / fund_transaction.rb
Created October 17, 2016 14:34
The class that inherits from ActiveRecord..
class FundTransaction < ActiveRecord::Base
belongs_to :fund_record_form2
validates_presence_of :reason_for_transaction
# def initialize(current_balance)
# super
# @current_balance || 0.0
# end
attr_accessor :deposit_amount, :withdrawal_amount
@sirramongabriel
sirramongabriel / bank_account.rb
Created October 17, 2016 14:31
This is the class not inheriting from Active Record, this works fine in the console..
class BankAccount
attr_accessor :name, :balance
def initialize(options={})
@name = options[:name]
@transactions = []
@balance = 0
end
def withdraw(amount)
@sirramongabriel
sirramongabriel / employee.rb
Created October 10, 2016 19:26
Describes associations on Employee (as admin)
class Employee < ActiveRecord::Base
belongs_to :account
validates :account_uid, presence: true
end
@sirramongabriel
sirramongabriel / account.rb
Created October 10, 2016 19:23
Describes association for Account
class Account < ActiveRecord::Base
has_one :admin, class_name: 'Employee', foreign_key: :account_id, dependent: :destroy
accepts_nested_attributes_for :admin, allow_destroy: true
end
@sirramongabriel
sirramongabriel / account.rb
Last active October 10, 2016 19:30
Shows how I attempt to create both and account and admin in the Accounts#new template
def new
@account = Account.new
@account.admin = Employee.new
@admin = @account.admin
@admin.is_admin = true
@admin.build_address
@admin.build_primary_phone
@admin.build_secondary_phone
@admin.build_primary_fax
end
@sirramongabriel
sirramongabriel / surveys#new.html.erb
Created April 22, 2016 15:06
snippet of jquery toggle for form_fields associated with a survey question
<%= form_for @survey, method: :post, class: "form-horizontal" do |f| %>
<div class="row">
<div class="panel panel-default col-md-12">
<% SurveyQuestion.all.map do |question| %>
<p>
<b><%= question.title %>:</b><br>
<%= question.description %>
</p>
<div class="row">
<div class="panel panel-default col-md-12">
source 'https://rubygems.org'
gem 'rails', '4.2.0'
gem 'pg'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'twitter-bootstrap-rails'
gem 'font-awesome-rails'
FactoryGirl.define do
factory :employee do
association :resident, factory: :resident
first_name { "bill" }
last_name { "clinton" }
email { "[email protected]" }
password { "12345678" }
dob { "1967-05-04" }
gender { "Male"}
end
FactoryGirl.define do
factory :resident do
association :employee, factory: :employee
end
factory :invalid_resident, parent: :resident do
end
end