Friday, September 22, 2006

Display salesforce.com account listing with Ruby on Rails

I would like to show you, how I did my first connection from Rails to salesforce.com. As an example I would like to display a listing of salesforce.com accounts on a web page.



Getting Started

Following the instructions on ActiveSalesforce (ASF) I installed ActiveSalesforce gem, created a Rails application and configured the application and database.




D:\projects>gem install activesalesforce --include-dependencies

D:\projects>rails sftest

D:\projects>cd sftest


Edit D:\projects\sftest\config\environment.rb and add the line require_gem 'activesalesforce'. If you forget to require the gem you will get an error message: database configuration specifies nonexistent activesalesforce adapter (ActiveRecord::AdapterNotFound).


Edit D:\projects\sftest\config\database.yml and add your salesforce.com account information.


adapter: activesalesforce

url: https://www.salesforce.com/services/Soap/u/7.0

username: salesforce-username

password: salesforce-password

Create module and controller.



D:\projects\sftest>ruby script/generate model account

D:\projects\sftest>ruby script/generate controller account

Edit D:\projects\sftest\app\controllers\account_controller.rb.



class AccountController < ApplicationController

  scaffold :account

end

Run the server and watch the result in your browser.



D:\projects\sftest>ruby sript/server



Resources

technorati tags:, , ,



Thursday, September 14, 2006

Error with mysql 2.7.1 gem

The last two days I was stuck tracking down the source of an error message. Running rake db:migrate or accessing the admin controller of the depot application I got the error message undefined method `each' for #<Mysql:0x352d430>.

I was experimenting with edge rails, Ruby 1.8.5. and MySQL 5.0.27 on Windows XP. rubyonrails.org recommends Ruby 1.8.4, but downgrading did not solve my problem.

To find the cause of the error, I did a clean install of Ruby 1.8.5 and Rails gem. Then I set up a test application:

  1. D:\projects>mysqladmin -u root -p create test
  2. D:\projects>rails test
  3. Edit D:\projects\test\config\database.yml
  4. D:\projects>rake db:migrate

The database connection was successful and no error message came up. So where did the message come from previously?

Then I remembered installing mysql 2.7.1. And yes, this is the cause!

Has anyone an idea why mysql 2.7.1 does not work?

technorati tags:, , ,

Friday, September 08, 2006

Getting started with Ruby on Rails

To get to know Rails, I recommend the "get exited" screencasts on rubyonrails.org. Then go get it installed on your computer! I used the Windows Installer from rubyforge.org. This sets a good base from which you could go further by installing gems (see the download page at rubyonrails.org).

Which editor to use is a very personal decision. Working with the command line and notepad++ on Windows was a good start for me. The magic of IDEs often hide details, which I find important to learn and master first.

I personally like learning by books. I bougt a pdf copy of "Agile Web Development with Rails - second edition". Several minutea after buying online, I began reading Part I. Following along the development of the Depot Application of Part II, I liked the links between different sections of the book and of course the links to the souce code. I am not reading online all the time, so I was looking for a way to use the links to the source offline.

To have the code available offline, I did download the code from the Pragmatic Programmers, put it in the document root of my local webserver and redirected the domain media.pragprog.com to localhost.

On Windows XP put the following line in C:\windows\system32\drivers\etc\hosts:

127.0.0.1 localhost media.pragprog.com

By the way, the pdf book is really well done. Links between sections of the book and to external ressources add value. Most of the time I prefer paper books over ebooks. If all ebooks were made like this one, my preferences would possibly change.

Halfway through the Depot Application I was looking for a more comfortable development environment. I like RadRails although it took some time to find out what configuration options to tweak and how it worked.

OK. Where are we now?

I have got a basic understanding of Ruby and Ruby on Rails. I could read some code and figure out what it does. So next I will have a look at some open-source applications to learn how they build their applications.

technorati tags:

Thursday, September 07, 2006

What this is all about

I started this Blog to document my learning Ruby on Rails conntecting to Salesforce.com. I would like to play with Rails as well as Salesforce.com integration (ActiveSalesforce). You'll be able to follow my step by step actions and find links to ressources I use to get me started.