just ram

stuff I should remember

Pluralize table names - no thanks!

Sorry I just can’t live with plural table names, I just can’t get my head around it! Luckily it is easily turned off. In RadRails there is a simple tick box when creating the project which simply adds the following line to the end of your applications config/environment.rb file:

# Include your application configuration below
ActiveRecord::Base.pluralize_table_names = false

I may live to regret not embracing plural table names but I doubt it!

Setting up Ruby on Rails

I’m going to give Ruby on Rails (RoR) a try on my Windows XP machine. Here’s how I’ve set it up…

  1. Install Ruby Using the Ruby One Click Installer Ruby One Click Installer (v184-16 release candidate 1)

  2. Setup proxy

set HTTP_PROXY=http://wwwcache:8080
  1. GEM install Ruby on Rails
gem install rails --include-dependencies
  1. Install RadRails I also downloaded and installed the latest RadRails (v0.6.1)

  2. Database I’m going to try rails with our dev MS-SQL server so no database to install. No doubt lots of configuring to do though!

NOTE:

There appears to be a problem with the WEBrick web server in this setup. I couldn’t find the answer on google but I did find a work around. If you run the WEBrick server using the standard ruby script\server you will get the following error:

ruby script\server
=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2006-04-04 13:20:35] INFO  WEBrick 1.3.1
[2006-04-04 13:20:35] INFO  ruby 1.8.4 (2005-12-24) [i386-mswin32]
[2006-04-04 13:20:35] WARN  TCPServer Error: Bad file descriptor - bind(2)
c:/ruby/lib/ruby/1.8/webrick/utils.rb:73:in `initialize': Bad file descriptor - bind(2) (Errno::EBADF)
        from c:/ruby/lib/ruby/1.8/webrick/utils.rb:73:in `create_listeners'
        from c:/ruby/lib/ruby/1.8/webrick/utils.rb:70:in `create_listeners'
        from c:/ruby/lib/ruby/1.8/webrick/server.rb:75:in `listen'
        from c:/ruby/lib/ruby/1.8/webrick/server.rb:63:in `initialize'
        from c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:24:in `initialize'
        from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:59:in `dispatch'
        from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/servers/webrick.rb:59
        from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
        from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in `require'
        from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/server.rb:30
        from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
        from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in `require'
        from script/server:3

There appears to be some problem binding to the port 3000, netstat shows nothing running on port 3000 so I’ve no idea what is causing it. Any hoose a work around is simply to run on another port:

ruby script\server --port=8000

If I do find out what is causing the problem I’ll update this post.

Tagging in subversion

We have started tagging our source when releasing to QA/porduction which means we can easily roll back to an ealier verison of the code if a problem is found in production. Here’s how we do it using TortoiseSVN.

First commit your source then open up the TortoiseSVN repository browser:

Right click in a folder in windows to get a context menu then select TortoiseSVN => Repo-Browser.

You should now see Repository browser:

Repository Browser

Find the trunk of the project you wish to tag then right click on the trunk folder and select ‘Copy to…’ from the context menu.

You will now see the Copy to… dialog:

CopyTo

Enter the path to your tagged copy, along the lines of svn://server/project/tags/Version2.00

You now have tagged version of your project which you can revert to anytime.

Ruby iteractive debugging

Buggy code, me? Never! If you have a problem with buggy code though your in luck ruby has a debugger baked in:

Simply run ruby with the debug flag:

ruby –r debug test.rb

USEFUL COMMANDS

list - List the source code, pass in a number range to filter the list. For example to list the lines 1 to 9:

list 1-9

b – Set a break point, pass a line number to break on. For example to break on line 7:

b 7

c – Continue program until breakpoint or end of program

disp – Display the contents of a variable. For example to see the contents of the look_at_me variable:

display look_at_me

watch – Set a watchpoint on a variable. For example to break when the variable meaning_of_life equals 42:

watch meaning_of_life=42
c

del – Delete a breakpoint or watchpoint. For example to delete the first breakpoint we created:

del 1

Ruby unit testing - Setting up your project folder for testing

Its a good idea to keep your test cases seperate from your production code:

  myproject
      lib/
          workomatic.rb
      test/
          test_workomatic.rb

When you have your project setup in this way add the following line to the top of your test cases:

Inside test_workomatic.rb

  $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
  require workomatic.rb

Now when you run this test case the workomatic.rb file and all supporting files in the lib folder will be picked up.

Ruby unit tests - run only one test method

What if you don’t wish to run all the unit tests in your test case?

You can tell ruby to run only one test method by passing in the name of the test:

  ruby test_mytestcase.rb --name test_just_this_method

SAP Portal: How do I reference a Javascript file in my iView?

Easy when you know how

public void doInitialization(){
  request = (IPortalComponentRequest)this.getRequest();
  response = (IPortalComponentResponse)this.getResponse();
  IResource jsResource = request.getResource(IResource.SCRIPT, “scripts/myscript.js”);
  response.addResource(jsResource);
}

How do I find the url of my SAP Portal Component?

Try this…

In SAP Netweaver Developer Studio

Open your project

Open the file:

MyPortalProject
    dist
        PORTAL-INF
            Portalapp.xml

You should now see a “Run…” button for each portal component in your project

Click the “Run…” button and the dev studio will open up a new browser window with the url to your component.

Installing Subclipse for SAP NetWeaver Developer Studio 2.0.13

First download the correct version of Subclipse:

Download the Eclipse 2.x version

Extract the zip file and copy the two folders:

org.tigris.subversion.subclipse.core_0.9.3.3
org.tigris.subversion.subclipse.ui_0.9.3.3

To your plugins folder, in my case:

C:\\Program Files\\SAP\\JDT\\eclipse\\plugins

Fire up the developer studio and you should now have the subversion perspective available.

Menu: Window => Open Perspective => Other…

Select SVN Repository Exploring from the dialog.

Right click on the SVN Repository windows to add a new repository:

Menu: New => Repository Location…

You will now see the following dialog:

New Repository Dialog

Simply enter your subversion server address and user/password if required.

You should now see your source code, right click on the Trunk folder of a project and select Check Out as Project.

Cogs will start turning and when finished you will have a shiny new project to play with.

Installing SAP Netweaver Developer studio

Before installing the studio you must first install the Java SDK:

j2sdk-142_06-windows-i586-p.exe

Just accept the defaults.

Now install Netweaver Depeloper studio (SP13 in my case)

NWDS_SP13\J2EE-RUNT-CD\IDE\JDTsetup.exe

Install all components.

You will be asked for the location of the Java SDK which if you accepted the default should be:

C:\j2sdk1.4.2_06

Next enter your proxy settings, wwwcache:8080 in my case.

Now sit back, relax and wait for the long install to finish!