Appirio's Tech Blog

Saturday, January 28, 2012

Tutorial - Getting Started with Rails & Databasedotcom Gem


It the new year again and time for resolutions. I made a resolution about a year ago to learn ruby. If you are looking for something to learn this year I would recommend ruby and here’s why:
  • Salesforce.com bought Heroku for $220M
  • Salesforce.com has been pushing “Open. Social. Mobile” for quite some time.
  • Ruby is great for creating social and mobile apps with open source technologies.
Do you see a correlation here? There are big things ahead for Force.com developers using Heroku. Eventhough Heroku is a polyglot platform, it shines with ruby. If you have the time, add ruby to your toolbox.

I presented this topic today at our Appirio Continuing Education webinar and thought it might come in handy for others trying to learn ruby. In the video I use the Databasedotcom gem to build a small app that displays a list of accounts, the details for a selected account and then queries for accounts by keyword. I reference some links to help you get started with ruby and rails and I’ve added them after the video.

You can find the source code here.



Links Referenced in the Video

Railsnstaller (Windows)
Homebrew
Ruby Version Manager (RVM)

Rails Guides
Railscasts
Rails for Zombies
Code School
Try Ruby
Ruby on Rails Tutorial
Ruby on Rails Documentation

Databasedotcom gem
Building and Deploying Great Applications with Salesforce, Ruby, and Heroku (Dreamforce)

17 comments:

  1. Awesome stuff as always Jeff. Thanks so much.

    ReplyDelete
  2. Thanks Jeff - all the resources I was looking for! Love Rails for Zombies

    ReplyDelete
  3. Great stuff.

    I am having trouble accessing sf custom objects, can you give a quick pointer on how to do that?

    ReplyDelete
    Replies
    1. Did you ever figure out your issue. I am also having trouble accessing sf custom objects.

      OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed):
      app/controllers/accounts_controller.rb:6:in `index'

      Any help is appreciated.

      Delete
    2. This comment has been removed by the author.

      Delete
  4. Great post - invaluable as I was new to rails, SFDC, and heroku. Speaking of that last - the application as you've laid it out here is not deployable to heroku because of its reliance on the sqlite3 gem. How do you work around that?

    ReplyDelete
  5. I've since figured out that you've got to swap in usage of postgresql instead of sqlite3 to make heroku happy (per their getting started guides). It's unfortunate that this requirement seems to cascade down to the dev environment, though - I had to set up a postgres database which isn't really being used.

    It seems weird that the databasedotcom gem's reliance on ActiveRecord kind of forces you to have some kind of database defined, even though it's not touching it. Am I missing something?

    ReplyDelete
  6. Thanks for posting this.

    I am having an issue connecting to sfdc.

    OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed):
    app/controllers/accounts_controller.rb:6:in `index'

    Has something changed since this was posted?
    Any help is appreciated.

    ReplyDelete
  7. databasedotcom.yml -
    client_secret: client secret
    client_id: client key
    debugging: true
    username: reuel3@gmail.com
    password: password+token
    host: login.salesforce.com

    ReplyDelete
  8. in salesforce remote access -
    callback url - http://localhost:3000
    contact email - my sfdc email

    ReplyDelete
  9. I'm currently using the databasedotcom gem as called for in this tutorial:
    http://techblog.appirio.com/2012/01/tutorial-getting-started-with-rails.html

    Any idea on setup, either on salesforce or rails that I need to implement?

    I have a databasedotcom.yml that looks like this:
    host: login.salesforce.com
    client_secret:
    client_id:
    debugging: true
    username: reuel3@gmail.com
    password:

    There was really no other configuration suggested.

    --------------
    More info. This is what I get when trying to connect to sf.
    I'm also using rails 3.2.3 now.

    I'm begging for help!

    Started GET "/" for 127.0.0.1 at 2012-05-14 13:48:11 -0400
    Processing by AccountsController#index as HTML
    Completed 500 Internal Server Error in 89ms
    OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=SSLv3 read server c
    ertificate B: certificate verify failed):
    app/controllers/accounts_controller.rb:6:in `index'

    Rendered c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.3
    /lib/action_dispatch/middleware/templates/rescues/_trace.erb (4.0ms)
    Rendered c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.3
    /lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.0
    ms)
    Rendered c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.3
    /lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues
    /layout (279.0ms)
    [2012-05-14 13:48:18] WARN Could not determine content-length of response body.
    Set content-length of the response or set Response#chunked = true

    ReplyDelete
  10. You shouldn't need to use HTTPS as your callback. Try using http://localhost:[port] as your Remote Access callback.

    ReplyDelete
  11. I am/was using http://localhost:3000 in my Remote Access callback. . .
    Can I configure so that I don't use https? :
    ***** REQUEST: https://login.salesforce.com//services/oauth2/token?grant_type=pa
    ssword&client_id=[client key]&client_secret=[client secret]&username=reuel3@gmail.com&password=[password and token]

    If I try to hit sf directly with the url above with http instead, it returns:

    invalid_request
    HTTPS required

    ReplyDelete
  12. Here are some instructions for setting up webrick: http://www.nearinfinity.com/blogs/chris_rohr/configuring_webrick_to_use_ssl.html

    ReplyDelete
  13. Thanks for speaking slowly, but I've been through that already resulting in this error when I hit my server:

    [2012-05-21 15:40:05] ERROR OpenSSL::SSL::SSLError: SSL_accept returned=1 errno=0 state=SSLv2/v3 read client hello A: http request
    c:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/openssl/ssl-internal.rb:164:in `accept'

    I get:
    ***** REQUEST: https://login.salesforce.com//services/oauth2/token?grant_type=pa
    ssword&client_id=[client key]&client_secret=[client secret]&username=reuel3@gmail.com&password=[password and token]
    when webrick is not configured.

    ReplyDelete
  14. Sorry that I can't help any further. I'm not sure how to troubleshoot this configuration.

    ReplyDelete
  15. I figured it out. I had to add this line to my databasedotcom.yml:
    verify_mode: OpenSSL::SSL::VERIFY_NONE

    It looks like starting with ruby 1.9.2, verify_mode defualts to VERIFY_PEER.

    Some further explantion can be found here:
    https://groups.google.com/group/activesalesforce/browse_thread/thread/40a06f8444bcada5/800c3487feb68...

    Thanks to all who pitched in.

    ReplyDelete

 
2006-2012 Appirio Inc. All rights reserved.
Appirio.com | Support | Resource Center | Contact | Careers | Privacy Policy