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() { | |
//Captures the click event | |
$('.choice').click(function(e) { | |
//extracts the value of the radio button that was clicked which | |
//corresponds to a JSON route. | |
var url = e.target.defaultValue | |
//makes the corresponding ajax call | |
ajax_call(url, update) | |
}); |
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
//Sets plot's dimensions and other relevant values as paddings | |
//and margins | |
var w = 1000 | |
var h = 1250 | |
var xPadding = 10 | |
var yPadding = 20 | |
var xMargin = 200 | |
var yMargin = 0 |
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 draw(dataSet) { | |
//Appends a svg element and sets its dimensions using w and h | |
svg = d3.select('body') | |
.append('svg') | |
.attr("width", w) | |
.attr("height", h) | |
.attr("class", "graph") | |
.append('g') | |
.attr("transform", "translate(" + xMargin + "," + yMargin + ")") | |
//Calculates the scales with the initial data set |
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 update(dataSet) { | |
//Calculates the scales from the data set | |
var scales = calculateScales(dataSet) | |
var xScale = scales[0] | |
var yScale = scales[1] | |
var yAxisScale = scales[2] | |
//Calculates the axes using the previous calculated scales | |
var axes = calculateAxes(xScale, yAxisScale) | |
var xAxis = axes[0] |
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 draw(dataSet) { | |
//Appends a svg element and sets its dimensions using w and h | |
svg = d3.select('body') | |
.append('svg') | |
.attr("width", w) | |
.attr("height", h) | |
.attr("class", "graph") | |
.append('g') | |
.attr("transform", "translate(" + xMargin + "," + yMargin + ")") | |
//Calculates the scales with the initial data set |
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 City < ActiveRecord::Base | |
has_many :libraries | |
end | |
class Library < ActiveRecord::Base | |
belongs_to :city | |
has_many :books | |
end | |
class Book < ActiveRecord::Base |
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
create_table "cities", force: :cascade do |t| | |
t.string "name" | |
t.integer "population" | |
t.boolean "is_capital" | |
t.string "major" | |
t.integer "area" | |
t.datetime "date_founded" | |
end | |
create_table "libraries", force: :cascade do |t| |
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 UsersController < ApplicationController | |
def create | |
@user = User.new(user_params) | |
if @user.save | |
flash[:success] = "Welcome to Monchitos. Hope you enjoy it!" | |
redirect_to posts_path | |
else | |
flash[:error] = "Sorry your registration could not be completed" | |
render :new | |
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 UsersController < ApplicationController | |
def create | |
@user = User.new(user_params) | |
if @user.save | |
#Sends the invitation email using the regular Rails mailers | |
AppMailer.welcome_email(@user) | |
if params[:invitation_token].present? | |
invitation = Invitation.find_by(token: params[:invitation_token]) |
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 UsersController < ApplicationController | |
def create | |
@user = UserSignupManager.perform(user_params, invitation_token) | |
if @user.errors.blank? | |
flash[:success] = "Welcome to Raysurfing. Hope you enjoy it!" | |
redirect_to posts_path | |
else | |
flash[:error] = "Sorry there was an error with your regitration" | |
render :new |