It has been almost a month since my last update... the time has really flown. The Tech Talent South program ends in the next two weeks, we are winding down and I am pleased with the amount that I have learned. Just a quick snapshot of some of the things I have been doing over the past month:A couple weeks ago we began implementing jQuery into some rails apps. We made an ATM app with js and gave it some simple logic. Once I began to understand the syntax I began seeing why everyone uses jQuery. I added a couple functions that change some css elements so the text displays red if the user tries to withdrawl more money than they have in the account. I also began playing around with allowing the user to hit the enter key after typing in the field instead of manually clicking with the mouse.
Code that allows user to hit enter when finished with number field:
function hitEnter(id, buttonid){
$("#enters").keyup(function(event){
if(event.keyCode == 13 && $(id).val() !== ''){
$(buttonid).click();
}
});
}
then I called the function six times and passed the appropriate id's.
hitEnter('#d_amount','#deposit')
hitEnter('#w_amount', '#withdrawl')
hitEnter('#x2c_amount', '#x2check')
hitEnter('#x2s_amount', '#x2save')
hitEnter('#dep_sav', '#d_saving')
hitEnter('#with_sav', '#w_savie')
I spent a good amount of time figuring out how to make the message turn red when a user requests more money than they had in their account. I eventually wrote two very simple functions that changed the css from red to black:
function red(){
$('#message').toggleClass('warning')
$('#message').text('you do not have enough money')
}
function backBlack(){
if ($('#message').hasClass('warning')){
$('#message').toggleClass('warning')
}
}
then called the functions like this:
$('#x2check').click(function(){
var amount = parseFloat($('#x2c_amount').val())
$('#x2c_amount').val('')
if (savings < amount){
alert("you do not have enough funds")
red()
} else {
backBlack()
savings -= amount
checking += amount
$('#message').text("Your transfer from savings to checking for quot; + amount + " was completed.")
}
})
Two of my favorite things we have done with rails over the past month was using Omniauth to allow user to sign in with an existing account like facebook or google+ and using google maps api and geocoder to that allowed users to find updated bus arrival times. For our facebook log in we used the omniauth gem with figaro to hide our API key's secret. We then used the omni_auth method to to create the user profile using the "provider" "userid" and "name" from facebook. For our bus app we set out to to create an app that would take an address from the user and then let the user know if there is a bus close by. We created a basic form to allow user input and stored nearby buses in an empty array after looping with a do loop. Using geocodes lat and longitude capabilities in our model, we then grabbed the bus system's api using a really cool gem called HTTparty that does all the parsing for us. We then implemented a live google map showing the location of the current bus using ajax.
Next week we will be working on more rails apps and I will finish the last bit of JavaScript on my portfolio site.
-John
No comments:
Post a Comment