You are currently browsing the monthly archive for November 2011.
In this tutorial we will go from zero to ninja speed in approximately ten minutes. If you have problems approaching ninja speed, it is probably because you are in ruby version management hell, gem dependency hell, or any other number of hells that brave would-be ninjas are occasionally trapped in. Should you end up here, prayer and Google may help you.
Step one: Create your rails app.
rails new ninjaspeed
Step two: Add the database.com and helper gem to your GEMFILE (this will be in the ninjaspeed directory)
gem 'databasedotcom' gem 'databasedotcom-rails'
Also add the postgres gem (you aren’t using the db on Heroku but need it anyways) and a gem to handle precompiled javascript (for the JQuery Mobile):
gem 'pg' gem 'therubyracer'
Step three: Install the new gems
sudo bundle install
Step four: Add scaffolding for a new resource that corresponds to a resource in Salesforce
rails generate scaffold_controller Lead FirstName:String LastName:String Company:String
Add an entry in your routes.rb file
resources :leads
Rails is straight up MVC, and you just created a controller and a view. Check out your app/controllers and app/views folders to see them. Salesforce/Database.com will be your Model.
Step five: Deploy this baby to Heroku
git init git add . git commit -m "i love databasedotcom" heroku create git push heroku master heroku addons add:piggyback_ssl
Step six: Take the new funky fantastic name you got and enable remote access in Salesforce
Login to salesforce. Go to Setup -> Develop -> Remote Access -> New Enter the address of your app (e.g. https://stormin'-samurai-558.herokuapp.com) You will get a client key (this is also the client_id) and your client secret
Step seven: Add your salesforce credentials to a file in the config folder called databasedotcom.yml
databasedotcom.yml #### client_id: 3MVG..... client_secret: 1323224123... username: mysalesforceusername@login.com password: passwordPlusSecToken host: login.salesforce.com <-- use test.salesforcecom if using a sandbox debugging: true
Step eight: Connect your app to Salesforce
Add this to your app/controllers/leads_controller
LeadsController < ApplicationController include Databasedotcom::Rails::Controller
In the same file you need to add a few more required fields. Navigate to the create method and add three lines:
def create
@lead = Lead.new(params[:lead])
# ADD ME
@lead['OwnerId'] = '005U0000000IekIIAS' <-- ownerId here is the Id of the User you want the Lead associated with
@lead['IsConverted'] = false
@lead['IsUnreadByOwner'] = true
# END
Thanks to some backend magic, the databasedotcom-rails gem automatically initializes the client you need to connect to salesforce so you don’t have to worry about it.
Step eight: Add in a jQuery mobile stylesheet so this doesn’t look super ghetto (optional)
Navigate to app/views/layouts/application.html.erb and edit these lines to the header:
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" /> <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script> <script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
Put the yield tag in the body in a div like so:
<div data-role="page"> <%= yield %> </div>
For your apps/views/leads/new.html.erb, divide into a couple of sections
<div data-role="header"> Lead form </div> <div data-role="content"> <%= render 'form' %> </div> <div data-role="footer"> If you want it </div>
Navigate to config/environments/production.rb, find the config.assets.compile, and set it to true (turn on the live compiliation of assets)
config.assets.compile = true
Step nine: Remove extra stuff from your _form.html.erb/strong
This is all you need:
<%= form_for(@lead) do |f| %>
<div class="field">
<%= f.label :FirstName %><br />
<%= f.text_field :FirstName %>
</div>
<div class="field">
<%= f.label :LastName %><br />
<%= f.text_field :LastName %>
</div>
<div class="field">
<%= f.label :Company %><br />
<%= f.text_field :Company %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Step ten: Deploy to Heroku
git add . git commit -m "I love databasedotcom even more now" git push heroku master
Navigate to yourapp.heroku.com/lead/new, and presto-chango, a mobile-enabled submission form that hooks up to Salesforce.
You can also view leads in the system by navigating to yourapp.heroku.com/leads
Also, if you want to add in validation (and I suggest it) you can do this client-side rather than serverside.
Oh, and in case you were wondering the source code for all this is available on Github.
Please contact your congressperson today.
You have a git submodule. You want to update it (e.g. get the newest freshest code). Here’s what
you do:
I’ve already initialized my submodule of course:
git submodule add git@github.com:mysubmodule mySubmoduleDir
At some point later I try this.
git submodule update
Ha ha you fool! This only gets you the copy that your submodule is already frozen at.
Try this instead:
cd mySubmoduleDirectory git checkout master git pull
Yes, I was the fool. You can go away now.
I stayed up until around three in the morning one night last week finishing this super addictive and awesome tutorial by jQuery creator John Resig.
I’ve been through some little ditty tutorials on closures and had people attempt to explain what it is before, but Resig’s tutorial is to your average online tutorial what a tanto is to a wiener.
Even though in a certain sense I’ve never met a wiener I didn’t like, I’d prefer that if you were fighting on my side you had a proper weapon –
and no matter how many skillz you got, it always helps to sharpen them.
Part of the reason I like this approach so much is that there is very little unnecessary baggage. You figure out what you need to by reading the code, with a few quizzes where you write some code so that the lessons sink in. As things stand I think the quizzes are a little bit under-developed, and as a whole it could probably be a bit more content as far as examples and gradually developing a theme, but hey JResig has a whole book coming out soon. Another fantastic feature is that you can edit each example as you go along, so if something is not immediately obvious you can tweak it or can add in the necessary log statements.
As far as this goes, I believe this is the future of programming education (and education in general). Less paper, less explanation, more interaction, more cementing of the material. In other words, less talking, more doing.
Keep in mind this is a Ninja-level tutorial, so it assumes a fair bit of knowledge of Javascript that you probably won’t have if you’ve just been waving around a wiener. That said and despite some rough edges, I will repeat and say it is the best online tutorial I have ever seen.
Here are some highlights:
Context – One of the funkier bits of JS.
Closures – Show don’t tell. Love it!
Function Prototypes – A lot you can do here but tricky to get right
Inheritance – You have to understand this well if you are doing any Advanced Javascript
Truly awesome is when you get to see how all the building blocks fit together towards the end of the book as Resig appropriate builds up to (rather than dissects) the Prototype bind function.
I end with this beautiful example:
var ninja = {
yell: function(n){
return n > 0 ? ninja.yell(n-1) + "a" : "hiy";
}
};
In case you were wondering, we are hiring ninjas over at Tquila.
Today I was performing some maintanence in Facebook and got caught in a wonderful infinite recaptcha loop, where Facebook asked me for my password, got it, asked me to fill out a recaptcha, I filled it out, and then kept asking me to fill out more and more recaptchas. I gave up after about ten. I tried again later and same problem.
If you are experiencing this problem, the solution is probably to switch accounts. In my case I was in as one of my Page accounts instead of my normal accounts. Once I switched back recaptcha worked as usual.
Hope this helps someone!
