Here I will describe how you can create a Rails Application in Eclipse using Craig Cmehils Scripting in a Box v0.1 with the Patches described in URL for the Ruby on Rails example in Scripting in a Box Version 0.1.0.
Install login_generator
Before you Start Eclipse I suggest that you put the C:DevelopmentApache
uby in folder into your PATH variable. So you can do the next step directly form the command line. You have to install the Gem Package login_generator. This is done by:
gem install login_generator
If your computer dont have direct internet access then you can Download the file login_generator-1.2.2.gem to your local disk and install it with:
gem install login_generator-1.2.2.gem
Create Rails Project
After youve started Eclipse please open File -> New -> Project. From the wizard choose a Rails Project:
I called my Project CSC which stands for Customer Service Centre and keep the default values:
Click Finish.
Configure SAP Backend Connection
To use a connection to a SAP Backend system we have to create a file called sap.yml in the config folder. To do this right click to this folder and opern New -> File:
Enter the File name sap.yml and insert this content:
development: ashost: lupomania.dyndns.org sysnr: "00" client: "800" user: sdncontest passwd: sdncontest lang: EN trace: "0"
Generate Login
Now you can go on by generating the Model/View/Controler for a login Screen. Swith to Generators and enter login and Account. Press Go.
You will see this files being generated:
Adopt Model
The generated Model/View/Controler is intended to authenticate Users against a Database Table called Users. To authenticate against SAP we have to modify the model. The model source file is located in app/models/user.rb. Navigate to this file and open it with a Doubleclick. This is the actual code:
require 'digest/sha1' require_gem "sap4rails" # this model expects a certain database layout and its based on the name/login pattern. # class User < ActiveRecord::Base class User < SAP4Rails::Base # You must define a list of RFCs to preload function_module :BAPI_PAR_EMPLOYEE_CHECKPASSWOR # You must define a list of attribute accessors to preload parameter :PARTNEREMPLOYEEID, :PASSWORD, :RETURN def self.authenticate(login, pass) RAILS_DEFAULT_LOGGER.warn("[User]#authenticate ") User.BAPI_PAR_EMPLOYEE_CHECKPASSWOR.reset() User.BAPI_PAR_EMPLOYEE_CHECKPASSWOR.PARTNEREMPLOYEEID.value = login User.BAPI_PAR_EMPLOYEE_CHECKPASSWOR.PASSWORD.value = pass User.BAPI_PAR_EMPLOYEE_CHECKPASSWOR.call() users = [] result = User.BAPI_PAR_EMPLOYEE_CHECKPASSWOR.RETURN.value if result['TYPE'] == "S" RAILS_DEFAULT_LOGGER.warn("[User]#authenticate - sucessfull") return true else RAILS_DEFAULT_LOGGER.warn("[User]#authenticate - " + result['MESSAGE']) return nil end end def change_password(pass) update_attribute "password", self.class.sha1(pass) end protected def self.sha1(pass) Digest::SHA1.hexdigest("change-me--#{pass}--") end before_create :crypt_password def crypt_password write_attribute("password", self.class.sha1(password)) end validates_length_of :login, :within => 3..40 validates_length_of :password, :within => 5..40 validates_presence_of :login, :password, :password_confirmation validates_uniqueness_of :login, :on => :create validates_confirmation_of :password, :on => :create end
The last thing you have to do is to adopt the first lines of the Application Controler app/controllers/account_controller.rb as described in the README_LOGIN file. It has to look like this:
require_dependency "login_system" class AccountController < ApplicationController include LoginSystem model :user layout 'scaffold'
Test Application
Now you can start the WEBrick Server by clicking on the Play button in the Servers Tab:
In the console Tab you will see when the Server was started successfully:
Now Point your local Browser to http://localhost:3000/account/login:
When you use my Demo Server then you can enter 111 for the Login and test1 for the Password. After youve click Login you should see: