Skip to content

Instantly share code, notes, and snippets.

View joelbrewer's full-sized avatar

Joel Brewer joelbrewer

View GitHub Profile
@joelbrewer
joelbrewer / factories.rb
Created January 15, 2014 23:22
My factories.rb file
FactoryGirl.define do
factory :user do
first_name "Joel"
last_name "Brewer"
email { "#{first_name}.#{last_name}@example.com".downcase }
password "booyabooya"
password_confirmation "booyabooya"
user_type "entrepreneur"
@joelbrewer
joelbrewer / conversations_controller.rb
Last active January 4, 2016 20:09
conversations_controller.rb
class ConversationsController < ApplicationController
before_filter :authenticate_user!
def create
conversation_params
recipient_email = params[:conversation][:recipients]
recipient = User.where(email: recipient_email)
current_user.send_message(recipient, params[:conversation][:body], params[:conversation][:subject]).conversation
end
@joelbrewer
joelbrewer / stack trace
Created January 28, 2014 18:11
stack trace
activerecord (4.0.0) lib/active_record/reflection.rb:391:in `primary_key'
activerecord (4.0.0) lib/active_record/reflection.rb:226:in `association_primary_key'
activerecord (4.0.0) lib/active_record/associations/belongs_to_association.rb:62:in `replace_keys'
activerecord (4.0.0) lib/active_record/associations/belongs_to_polymorphic_association.rb:13:in `replace_keys'
activerecord (4.0.0) lib/active_record/associations/belongs_to_association.rb:14:in `replace'
activerecord (4.0.0) lib/active_record/associations/singular_association.rb:17:in `writer'
activerecord (4.0.0) lib/active_record/associations/builder/association.rb:78:in `receiver='
mailboxer (0.11.0) app/models/message.rb:64:in `block in build_receipt'
mailboxer (0.11.0) app/models/message.rb:61:in `tap'
mailboxer (0.11.0) app/models/message.rb:61:in `build_receipt'
@joelbrewer
joelbrewer / gist:8713762
Last active August 29, 2015 13:55
new project form
%h1 New Project
= form_for @project do |f|
= render 'shared/error_messages', object: f.object
%div
= f.label :title
= f.text_field :title
%div
= f.label :contact_name
= f.text_field :contact_name
%div
@joelbrewer
joelbrewer / gist:8713830
Created January 30, 2014 17:22
projects controller
class ProjectsController < ApplicationController
before_filter :authenticate_user!
before_action :correct_user, only: :destroy
def create
@project = current_user.projects.build(project_params)
if @project.save
flash[:success] = "Project created!"
redirect_to profile_path
else
@joelbrewer
joelbrewer / gist:8713922
Created January 30, 2014 17:26
project model
class Project < ActiveRecord::Base
belongs_to :user
validates :user_id, presence: true
validate :project_count_within_limit, :on => :create
validates :title,
:contact_name,
:email_address,
:phone_number,
:description,
:category,
@joelbrewer
joelbrewer / projects_controller_spec.rb
Last active August 29, 2015 13:55
projects_controller_spec.rb
require 'spec_helper'
describe ProjectsController do
let(:user) { FactoryGirl.create(:user) }
describe "GET #index" do
context "when user is not signed in" do
it "redirects to sign up page" do
@joelbrewer
joelbrewer / gist:8732709
Created January 31, 2014 14:09
params passed to controller through page
{"utf8"=>"✓",
"q"=>{"category_cont"=>"asian_restaurant", "sub_category_cont"=>""},
"commit"=>"search",
"action"=>"index",
"controller"=>"projects"}
%nav
%ul
= render 'layouts/all_user_links'
- if signed_in?
- if current_user.investor?
= render 'layouts/investor_links'
- if current_user.entrepreneur?
= render 'layouts/entrepreneur_links'
= render 'layouts/all_signed_in_user_links'
- else
NameError in ProjectsController#new
uninitialized constant User::Project
Extracted source (around line #25):
def new
@project = current_user.build_project
@categories = ProjectCategory.all
end