Commit
Updated .gitignore with more temp files;
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ | ||
jQuery -> | ||
$('#new_commute').bind 'ajax:success', (event, data, status, xhr) -> | ||
console.log data | ||
$('#cash_score').text data.cash_score | ||
$('#cal_score').text data.cal_score | ||
$('#envfp_score').text data.envfp_score | ||
$('.score').show() | ||
.bind 'ajax:error', -> | ||
alert 'No!' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,8 +44,11 @@ def create | |
|
||
respond_to do |format| | ||
if @commute.save | ||
redirect_to dashboard_path(@commute), notice: 'Commute was successfully created.' | ||
format.json { render json: @commute, status: :created, location: @commute } | ||
format.html { render action: "show" } | ||
format.json { render json: @commute.attributes.merge({:cal_score => @commute.cal_score, | ||
:cash_score => @commute.cash_score, | ||
:envfp_score => @commute.envfp_score | ||
}), status: :ok, location: @commute } | ||
else | ||
format.html { render action: "new" } | ||
format.json { render json: @commute.errors, status: :unprocessable_entity } | ||
|
@@ -60,8 +63,11 @@ def update | |
|
||
respond_to do |format| | ||
if @commute.update_attributes(params[:commute]) | ||
redirect_to dashboard_path(@commute), notice: 'Commute was successfully update.' | ||
format.json { head :no_content } | ||
format.html { render action: "show" } | ||
format.json { render json: @commute.attributes.merge({:cal_score => @commute.cal_score, | ||
:cash_score => @commute.cash_score, | ||
:envfp_score => @commute.envfp_score | ||
}), status: :ok, location: @commute } | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
misttar
Collaborator
|
||
else | ||
format.html { render action: "edit" } | ||
format.json { render json: @commute.errors, status: :unprocessable_entity } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,28 +11,34 @@ class Commute < ActiveRecord::Base | |
def cash_score | ||
# calculate cash score | ||
# car cash value - other cash value | ||
if cash_fr | ||
(CommuteType.baseline.cash - cash) | ||
else | ||
(CommuteType.baseline.cash * distance) * (1 + passenger) - (cash * distance) | ||
if id? | ||
This comment has been minimized.
Sorry, something went wrong.
vosechu
|
||
if cash_fr | ||
(CommuteType.baseline.cash - cash) | ||
else | ||
(CommuteType.baseline.cash * distance) * (1 + passenger) - (cash * distance) | ||
end | ||
end | ||
end | ||
|
||
def cal_score | ||
# calculate calories score | ||
if calories_fr | ||
calories | ||
else | ||
calories * distance | ||
if id? | ||
if calories_fr | ||
calories | ||
else | ||
calories * distance | ||
end | ||
end | ||
end | ||
|
||
def envfp_score | ||
# calculate envfp score | ||
if envfp_fr | ||
(CommuteType.baseline.envfp - envfp) | ||
else | ||
(CommuteType.baseline.envfp * distance) * (1 + passenger) - (envfp * distance) | ||
if id? | ||
if envfp_fr | ||
(CommuteType.baseline.envfp - envfp) | ||
else | ||
(CommuteType.baseline.envfp * distance) * (1 + passenger) - (envfp * distance) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,9 @@ | |
|
||
root :to => 'dashboard#intro' | ||
|
||
match '/dashboard' => 'dashboard#main' | ||
match 'dashboard' => 'dashboard#main' | ||
|
||
get 'dashboard/:id', :to => 'dashboard#show' | ||
match 'dashboard/:id', :to => 'dashboard#show', :as => 'dashboard' | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
misttar
Collaborator
|
||
|
||
# The priority is based upon order of creation: | ||
# first created -> highest priority. | ||
|
Serializer objects would help reduce this duplication a little bit. Easier to do
render json: CommuteSerializer.new(@commute)
. Now you can run tests and ensure that status and location are getting set correctly. Otherwise I would worry about coworkers mangling it. JSON is so delicate sometimes.