This file contains 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
.... | |
returned_results: 0, | |
initialize: function() { | |
var self = this; | |
this.collection = new People(); | |
_.each(rocketeers, function(person) { | |
$.getJSON(person.get("search_url"), function(data) { |
This file contains 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 Person = Backbone.Model.extend({ | |
defaults: { | |
img_url: '', | |
name: '', | |
hugs: 0, | |
}, | |
refresh_hugs: function() { | |
var self = this; | |
$.getJSON(this.get("search_url"), function(data) { |
This file contains 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
<body> | |
<div id="hug_a_rocketeer"> | |
<ul id="rocketeers"> | |
<li> | |
<div id='pic_and_name'> | |
<img src='http://dummyimage.com/50x50/574b57/bcbfeb.png'/> | |
<span> Marian Phalen </span> | |
</div> | |
<ul id="props"> | |
<li> 3 Hugs </li> |
This file contains 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 CandidatesController < ApplicationController | |
expose(:candidates) { Candidate.search(params[:search]).order(:first_name) } | |
def search | |
render :index | |
end | |
end |
This file contains 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
.search | |
= form_tag search_candidates_path, method: :post do | |
%fieldset | |
= text_field_tag :search, params[:search] | |
= submit_tag "Search" | |
%table.standard | |
%thead | |
%tr | |
- ["Name", "Phone", "Email", "Github", "Twitter", "Local", "Willing to Relocate"].each do |th| |
This file contains 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 Candidate < ActiveRecord::Base | |
scope :search, ->(term) { term.blank? ? {} : where("full_name like ?", "%#{term}%") } | |
before_save :denormalize_name | |
private | |
def denormalize_name | |
self.full_name = [first_name, last_name].join(' ') |
This file contains 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 CandidatesController < ApplicationController | |
expose(:candidates) { Candidate.order(:first_name) } | |
expose(:search_term) { params[:search] } | |
expose(:search_results) { Candidate.search(search_term) if search_term } | |
def search | |
render :index | |
end | |
end |
This file contains 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 Candidate < ActiveRecord::Base | |
before_save :denormalize_name | |
def self.search(term) | |
term.blank? ? Candidate.all : where("full_name like ?", "%#{term}%") | |
end | |
private |
This file contains 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 AddFullNameColumnToCandidates < ActiveRecord::Migration | |
def self.up | |
add_column :candidates, :full_name, :string | |
end | |
def self.down | |
remove_column :candidates, :full_name | |
end | |
end |
This file contains 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 'spec_helper' | |
describe Candidate do | |
subject { Fabricate(:candidate, first_name: "Joe", last_name: "Doe") } | |
describe "#full_name" do | |
its(:full_name) { should == "Joe Doe" } | |
end | |
describe "#search" do |