Introduction

There has been so many plugins in ruby on rails space and we have been always re-inventing the wheel and writing again and again… Why do we do that? One of the main reasons are that many plugins have been built are for particular reasons and they haven’t integrated them. One of the similar plugins I am talking is about the country_select and state_select. One is used to select the countries and another to select the state. What happened to the regions…should we write one more plugin to say region_select or continent_select? …. This motivated me to integrate all the plugins so that we have one plugin… When I started to write the geography_division_select I had in mind that I want to integrate regions, countries and states. But by the time implementation completed I had added multiple features such as conditioins, priority list and selected options.

what does GEOGRAPHY_DIVISION_SELECT do?

Geography Division Select is a select tag which helps developers to display all divisions of the World. This plugin is similar to the country_select and state_select plugins and includes both mechanisms.

 

  1. Using Geography Division Select a user can
  2. List all the Regions (Continents) of the world (based on conditions)
  3. List all the Countries of the world (based on conditions)
  4. List all the States/Provinces/Districts…etc., for Each(or more) Country(ies)(based on conditions)
  5. Provide drill downs based on :o nly and :exclude conditions
  6. Support Priority Listing
  7. Support preselected listing

 

Geography Division Select can be used by 4 methods

 

  1. By using geography_division_select with object and method and option. This creates a HTML SELECT tag along with OPTION tags
  2. By using rails select_tag and sending the options by use of geography_division_options_for_select
  3. By using HTML SELECT tag and wrapping around Option Tags  by use of geography_division_options_for_select.
  4. By using geography_division_select as part of Form Tag.

 

Who are the authors of acts_as_fannable?

Satish Kota. He is the founder and chief technical architect of Heurion Consulting Pvt Ltd. A small RoR shop based in Bangalore, India. We have been providing exciting RoR services. Visit our website www.heurionconsulting.com

Where is Geography_division_select plugin available?

It is available in git. The public clone to this git is

git clone git://github.com/heurionconsulting/geography_division_select.git

How to use geography_division_select ?

 

Geography Division select can be used in 2 methods

 

1. Select tag which generates the HTML SELECT and OPTION TAGS

 

geography_division_select(object,method,options,html_options)

 

2. Select tag which generates just OPTION TAGS which can be wrapped around a HTML SELECT TAG

 

geography_division_options_for_select(options)

 

The main entity that controls the display of geography_division_select is the options section. The main supporting elements are

 

:drilldown — This keyword identifies the type of data to be shown as part of dropdown. Supporting types of drilldown are

            :drilldown=>”region” — displays the regions (continents) of the world based on conditions. This is the default type of drilldown

            :drilldown=>”country” – displays the countries of the world based on conditions

            :drilldown=”state” – displays the states/provinces/atolls/islands,etc., of a country(ies) based on conditions

 

:selected – This keyword identifies which option in the dropdown has to be preselected.

 

:priority – This keyword identifies if there is any priority selection that has to be provided along with the complete list.

This helps if the developer wants to ensure priority for a particular country/state/region.

 

:o nly – This keyword provides support to identify conditions for the drilldown to provide display of that particular or set of drilldown elements.

Only Conditions has to be used in conjunction of the drilldown type to identify better selection of drilldown data.

 

:exclude — This keyword provides support to exclude a list of options while creating the dropdown options. Just like :o nly conditions, :exclude conditons

can be used in conjunction of the drilldown types to allow better selection of drilldown data.

 

NOTE: 

 

1. :o nly and :exclude conditions can have multiple drilldowns as part of the conditions. It helps in making correct query of options that are displayed

 

e.g.       a. :o nly=>{:country=>”United States Of America”,:region=>”North America”}

            b. :exclude=>{:country=>”India”, :state=>”Karnataka”}

 

2. For any select tag both :o nly and :exclude can be used together.

 

e.g. {:only=>{:region=>”Asia”,:country=>”India”},:exclude{:state=>”Karnataka”}}

 

3. Any conditions either in :o nly or :exclude you can use multiple elements (separated by comma)

 

e.g.       a. :o nly=>{:country=>”India,United States of America, United Kingdom,France,Spain”}

            b. :exclude=>{:region=>”Africa,Asia,North America”}

            c. :o nly=>{:region=>”Asia,Africa,North America”},:exclude=>{:country=>”India,United States Of America,South Africa”}

 

4. By using Only conditions care has to be taken to ensure that the parent of the drilldown would be neglected. The various options are

            a. only has region drilldown — both country and state are considered if they are part of :exclude condition

            b. only has country drilldown — only state is considered if it is part of :exclude condition. if region is part of :o nly or :exclude condition it is not considered for calculation of states

            c. only has state drilldown — only the state is considered. If region or country is part of :o nly or :exclude condition, they are neglected for calculation of list of states

 

e.g.       a. :o nly=>{:region=>”Asia”},:exclude=>{:country=>”India”,:state=>”Karnataka”} — Valid

            b. :o nly=>{:country=>”India”},:exclude=>{:region=”North America”} — same as :o nly=>{:country=>”India”}

            c. :o nly=>{:region=>”Asia”,:country=>”India”} — same as :o nly=>{:country=>”India”}

            d. :o nly=>{:state=>”Washington”},:exclude=>{:region=>”Asia”} — same as :o nly=>{:state=>”Washington”}

            e. :o nly=>{:state=>”Washington”},:exclude=>{:region=>”Asia”,:country=>”United States of America”} — same as :o nly=>{:state=>”Washington”}

            e. :o nly=>{:country=>”United States of America”,:state=>”Washington”},:exclude=>{:region=>”Asia”}– same as :o nly=>{:state=>”Washington”}

            f. :o nly=>{:region=>”North America”,:state=>”New York”},:exclude=>{:country=>”United States of America”}– same as :o nly=>{:state=>”New York”}

            g. :o nly=>{:region=>”North America”,:country=>”United States of America”,:state=>”New York”} — same as :o nly=>{:state=>”New York”}

Thats it you are ready to use the plugin.

Any Examples?

Currently as part of the Read me file, I have listed about 20 examples, but till date there are about 38 different combinations that can be created. The first 20 examples are listed below for your perusal.

<p>

=======================================================================<br/>

You can just copy and paste all these examples in a view (rhtml or html.erb file) to get a better understanding of the options <br/>

=======================================================================

</p>

 

<p>Examples using geography_division_select tag<br/>

============================================

 

<p>Example 1: Default Entity

<%= geography_division_select(“geography”,”geography”) %></p>

Displays all the 7 regionsof the world

 

 

 

<p>Example 2: Region DrillDown

<%= geography_division_select(“geography”,”geography”,:drilldown=>”region”) %></p>

Displays all the 7 regions of the world

 

 

 

<p>Example 3: Region Drilldown using Region Only Conditions

<%= geography_division_select(“geography”,”geography”,:drilldown=>”region”,:only=>{:region=>”Europe,North America,South America”}) %></p>

Displays the 3 regions as set in the :o nly conditions

 

 

 

<p>Example 4: Region Drilldown using Region Exclude Conditions

<%= geography_division_select(“geography”,”geography”,:drilldown=>”country”,:exclude=>{:region=>”North America,South America”}) %></p>

Displays the all the regions of the world except regions declared in :exclude condition

</p>

 

 

 

<p>Examples using the normal select tag and geography_division_options_for_select <br/>

======================================================================

 

 

 

<p>Example 5: Country Drilldown

<%= select_tag(“geography”,geography_division_options_for_select(:drilldown=>”country”)) %></p>

Displays all the countries in the world

 

 

 

<p>Example 6: Country Drilldown with Country Only Conditions

<%= select_tag(“geography”,geography_division_options_for_select(:drilldown=>”country”,:only=>{:country=>”India,United States of America,United Kingdom”})) %></p>

Displays only the countries as listed in the :o nly conditions

 

 

 

<p>Example 7: Country Drilldown with Country Exclude Conditions

<%= select_tag(“geography”,geography_division_options_for_select(:drilldown=>”country”,:exclude=>{:country=>”India,United States of America,United Kingdom”})) %></p>

Displays all the countries in the world except the ones listed in the :exclude conditions

 

 

 

<p>Example 8: Country Type Region Only Conditions

<%= select_tag(“geography”,geography_division_options_for_select(:drilldown=>”country”,:only=>{:region=>”Asia,Europe”})) %></p>

Displays all the countries in the Asia and Europe Region.

 

</p>

<p>Examples using the geography_division_select as part of the form tag<br/>

=====================================================================

 

<% form_for :user do |f| -%>

 

<p><label for=”region”>Example 9: Country Drilldown using Region in Exclude Conditions</label><br/>

<%= f.geography_division_select :geography,:drilldown=>”country”,:exclude=>{:region=>”Asia,Europe”} %></p>

Displays all the countries in the world except the countries in the asia and europe region

 

 

 

<p><label for=”region”>Example 10: Country Drilldown using Region and Country in Only Conditions</label><br/>

<%= f.geography_division_select(“geography1″, :drilldown=>”country”,:only=>{:region=>”Asia,Europe”,:country=>”India,UnitedKingdom,France,Indonesia”}) %>

</p>

Displays all the countries as available in the :o nly conditions

 

 

 

<p><label for=”region”>Example 11: Country Drilldown using Region in Only and Country in Exclude Conditions</label><br/>

<%= f.geography_division_select :geography2, :drilldown=>”country”,:only=>{:region=>”Asia,Europe”},:exclude=>{:country=>”India,UnitedKingdom,France,Indonesia”} %></p>

Displays all the countries in the Asia and Europe Region except the countries listed in the :exclude conditions

 

 

 

<p><label for=”country”>Example 12: Country Drilldown using Region in Exclude and Country in Only Conditions</label><br/>

<%= f.geography_division_select :geography3,:drilldown=>”country”,:exclude=>{:region=>”Asia,South America”},:only=>{:country=>”India,Japan,South Africa”} %></p>

Displays all the countries listed in the :o nly conditions

 

 

 

<p><label for=”country”>Example 13: Country Drilldown using Region and Country in Exclude Conditions</label><br/>

<%= f.geography_division_select :geography4,:drilldown=>”country”,:exclude=>{:region=>”Asia,South America”,:country=>”France,United States of America,United Kingdom”} %></p>

Displays all the countries which are not part of Asia and South America regions and the countries listed in the :country exclude section.

 

 

 

<p><%= submit_tag ‘Submit’ %></p>

 

<% end -%>

</p>

 

<p>Examples using the HTML SELECT TAGS with options created using geography_division_options_for_select <br/>

 

 

 

<p>Example 14: State Drilldown using Country only State only Conditions

<select name=”geography”>

<%= geography_division_options_for_select(:drilldown=>”state”,:only=>{:country=>”India”,:state=>”Karnataka,Delhi,Himachal Pradesh”}) %></select>

</p>

Displays all the states listed in the state’s only condition

 

 

 

<p>Example 15: State Drilldown using Country in Only and State in Exclude Conditions

<select name=”geography”>

<%= geography_division_options_for_select(:drilldown=>”state”,:only=>{:country=>”India”},:exclude=>{:state=>”Karnataka,Himachal Pradesh”}) %></select>

</p>

Displays all the states of India  country excluding the states listed in the :exclude conditions

 

 

 

<p>Example 16: State Drilldown using Country in Exclude and State in Only Conditions

<select name=”geography”>

<%= geography_division_options_for_select(:drilldown=>”state”,:exclude=>{:country=>”India”},:only=>{:state=>”Karnataka,Himachal Pradesh”}) %></select>

</p>

Displays all the states as listed in the Only conditions

 

 

 

<p>Example 17: State Drilldown using Country in Only conditions

<select name=”geography”>

<%= geography_division_options_for_select(:drilldown=>”state”,:only=>{:country=>”India”}) %></select>

</p>

Displays all the states of India

 

 

 

<p>Example 18: State Drilldown using Country in Only conditions

<select name=”geography”>

<%= geography_division_options_for_select(:drilldown=>”state”,:only=>{:country=>”India,United Kingdom”}) %></select>

</p>

Displays all the states of India and United Kingdom

 

</p>

 

<p>Examples using the Selected option<br/>

====================================

 

<p>Example 19: State Drilldown using Country in Only conditions and Selected

<select name=”geography”>

<%= geography_division_options_for_select(:drilldown=>”state”,:only=>{:country=>”India,United Kingdom”},:selected=>”Greater London”) %></select>

</p>

Displays all the states of India and United Kingdom with London being selected

 

</p>

 

<p>Examples using the priority option<br/>

====================================

 

<p>Example 20: Region Drilldown using prority regions

<%= geography_division_select(“geography”,”geography”,:drilldown=>”region”,:priority=>”Asia,North America,Europe”) %></p>

Displays all the 7 regions of the world with Asia, North America and Europe in the priority segment

 

 

 

<p>Example 21: Country Drilldown using Priority items

<%= geography_division_select(“geography”,”geography”,:drilldown=>”country”,:priority=>”United States Of America,United Kingdom,India”) %></p>

Displays all the 239 countries of the world with USA, UK and India being in the priority list.

</p>

Is this It or any thing is more pending?

I have tried my level best to implement everything, however there is still formatting options that I need to provide. Currently when a developer selects a country only countries will be listed and so is with regiond and states.

However I have a plans to implement formatting options such that we display a drill down mechanism to allow users to view the dropdown in a much better fashion.

So much for the next version.

Disclaimer

The list of Regions, Countries, States/Provinces/Districts/Atolls/Islands, etc., are based on informatoin collected in the internet.

We are thankful to various sites  especially to Wikipedia.org for having provided the information. All the data provided have been converted into

pure english alphabet format and special characters are converted to its nearest english alphabet. The authors have tried their level best to provide

adequate and correct information based on the analysis and takes no responsiibility if so ever if any information is incorrect or is in form that

offend any users. The authors acknowledges if any error is brought to notice and shall make necessary changes. Please review the data carefully before you use them.

 

All issues and inappropriate data can be brought into the notice of info@heurionconsulting.com

Licensing?

We follow MIT License. Look out for the MIT-LICENSE file in the plugin folder

Introduction

Bookmark_url_to is the second plugin that I wrote to provide support for ruby on rails programmers to allow them speed up their programming activities. I had gone through 2 more plugins before I decided to write a new one.  I felt there were more work for the developers to understand and co-ordinate in building their applications with plugins. However i still feel the existing plugins are cool… Also I wanted to include multiple options such as showing images or text or both OR show your own text, right at the time of writing the code.

what does Bookmark_url_to  do?

bookmark_url_to provides support for users to connect thier url and titles to 57 social bookmarking sites including digg, technorati, delicious, comments, google, yahoo,etc.,. bookmark_url_to supports bookmarking to Browser Favorites and also if you want to send a particular url to your friend through your mail application. 

The various sites that we support are

Allows users to Bookmark their pages to standard websites

1. BlinkBits (:blinkbits)
2. BlinkList (:blinklist)
3. BlogMarks (:blogmarks)
4. BlogMemes (:blogmemes)
5. BlueDot (:bluedot)
6. Bumpzee (:bumpzee)
7. Co.mments (:comments)
8. Connotea (:connotea)
9. Del.icio.us (:delicious)
10. De.lirio.us (:delirious)
11. Digg (:digg)
12. Diigo (:diigo)
13. DotNetKicks (:dotnetkicks)
14. Dzone (:dzone)
15. Fark (:fark)
16. Facebook (:facebook)
17. Favorites (:favorites) — (Add Favorites in Browser)
18. FeedmeLinks (:feedmelinks)
19. Fleck (:fleck)
20. FriendSite (:friendsite)
21. Furl (:furl)
22. Google (:google)
23. IceRocket(:icerocket)
24. Kaboodle (:kaboodle)
25. LinkAGoGo (:linkagogo)
26. Ma.gnolia (:magnolia)
27. MailTo (:mailto) — open e-mail editor(outlook)
28. Maple (:maple)
29. MisterWong :misterwong)
30. MySpace (:myspace)
31. Netscape (:netscape)
32. NetVouz (:netvouz)
33. Newsvine (:newsvine)
34. PlugIm (:plugim)
35. PopCurrent (:popcurrent)
36. Propeller (:propeller)
37. RawSugar (:rawsugar)
38. Reddit (:reddit)
39. Rojo (:rojo)
40. ShoutWire (:shoutwire)
41. Simpy (:simpy)
42. Sk*rt (:skirt)
43. SlashDot (:slashdot)
44. SphereIt (:sphere)
45. Spurl (:spurl)
46. Squidoo (:squidoo)
47. StumbleUpon (:stumbleupon)
48. Taggly (:taggly)
49. TailRank (:tailrank)
50. Technorati (:technorati)
51. ThisNext (:thisnext)
52. Twitter (:twitter)
53. WebRide (:webride)
54. Wists (:wists)
55. Vigillar (:vigillar)
56. Yahoo (:yahoo)
57. WindowsLive (:live)

 

Who are the authors of bookmark_url_to?

Satish Kota. He is the founder and chief technical architect of Heurion Consulting Pvt Ltd. A small RoR shop based in Bangalore, India. We have been providing exciting RoR services. Visit our website www.heurionconsulting.com

Where is bookmark_url_to plugin available?

It is available in git. The public clone to this git is git://github.com/heurionconsulting/bookmark_url_to.git

 

 

How to use bookmark_url_to ?

Using bookmark_url_to is very simple and easy. There are no models or controllers or database tables created. All you have to do is run the installation and call one method in your view as per your requirement. You might have to include a stylesheet that gets created in your stylesheets folder. Follow the below code

Post Installation Activity 

 * Once installation is doneall you have to do is to call the below 2 lines of code in your Views i.e. where you want to show the url links<%= stylesheet_link_tag “bookmark_url_to” %>

<%= apply_bookmark_url_to(url,title,sites,options) %>

where

url -> URL of that page which you want to bookmark e.g. http://localhost:3000/product/show/1 or http://localhost:3000/product/my_product_item

title -> title in which the url has to be bookmarked e.g. my_product_item

sites -> Collection of all the sites to which you want to associate your url and title to.

conditions-> [:all] — Associate this to allow all the 58 links to be added to the list

[:google, :facebook, :myspace,....] — Show only google, facebook, myspace elements in the list

options -> There are 2 options that could be added to execute this plugin

:text –> In this Option you can give the text that you want to show to the viewers before you

see the site links (generally it is “share”). By default this options is set to empty

:visibility_type –> This option is used to control the visibility type. There are only 3 types listed

“image” –> Show only image of the sites

“text” –> Show only the site names

“both” –> Show both image and text

:site_text –> This option is to replace any of the standard text that you want to show to the user instead of the standard text.

If you use this option then the text will be replaced in the text as visible to the user and in the alt section

of the image element.

Styling the application

When ever you install the plugin and run the server after installation, some of the files get loaded into the system. One of these are

bookmark_url_to.css which has necessary divs and classes can be styled. The styled elements are

#bookmark_url_to{..put your styling code here } this is the outer div

which you can style to set width

.bookmark_url_to_element{…put your styling code here} this is the div for each

of the div where each type of site is selected.

.bookmark_url_to_text{…put your styling code here} this div is for the div where you want to add you text.

Examples?

 

 

 1. example method call for all sites would look like<%= apply_bookmark_url_to(“http://localhost:3000/”,”TEST”,[:all],{:text=>”share : “,:visibility_type=>”text”}) %>

2. example method call for all sites to show both image and text

<%= apply_bookmark_url_to(“http://localhost:3000/”,”TEST”,[:all],{:text=>”share : “,:visibility_type=>”both”}) %>

3. example method call for a few set of sites to show only image

<%= apply_bookmark_url_to(“http://localhost:3000/”,”TEST”,[:google,:facebook,:myspace, :favorites,:digg,:technorati],{:text=>”share : “,:visibility_type=>”image”}) %>

4. example method call for all sites to show text in required format

<%= apply_bookmark_url_to(“http://localhost:3000/”,”TEST”,[:all],{:text=>”share : “,:visibility_type=>”both”,:site_text=>{:delicious=>”del.icio.us”,:delirious=>”de.lirio.us”,:comments=>”co.mments”}}) %>

 

Licensing?

We follow MIT License. Look out for the MIT-LICENSE file in the plugin folder

Introduction

When I was implementing some projects for our clients, I came across multiple activities where we used quite a lot of acts_as_XXX plugins… some of  them well known and vastly used were acts_as_commentable, acts_as_taggable, acts_as_rateable…etc., However when a new requirement came in from some no where where we wanted to implement a system where the client wanted to implement fans for all the users and also for games. Then the idea struck as to why not make a plugin to allow others to use this feature

what does ACTS_AS_FANNABLE  do?

acts_as_fannable is a simple plugin written to help Ruby on Rails Models to associate fans to it..e.g.. People can have fans, Books can have fans, Items can have fans, sports can have fans etc.,. This project helps ruby on rails programmers with a system to implement fannable situation.

Who are the authors of acts_as_fannable?

Satish Kota. He is the founder and chief technical architect of Heurion Consulting Pvt Ltd. A small RoR shop based in Bangalore, India. We have been providing exciting RoR services. Visit our website www.heurionconsulting.com

Where is acts_as_fannable plugin available?

It is available in git. The public clone to this git is git://github.com/heurionconsulting/acts_as_fannable.git 

 

How to use acts_as_fannable ?

Acts_as_fannable is much similar to Juxie’s acts_as_commentable. We have picked the idea from there. All you have to do is follow the Read me file. However to the benefit of users. The below code is what you can use from.

I  Creating the migration File

Creating a migration file is very necessary because we need a database to create and store the fans for the models. we suggest you follow the below steps to do the activity.

a. creating migration file

./script/generate migration acts_as_fannable

The code creates a file in db/migrate/20090130102017_acts_as_fannable.rb where you need to enter the details of the table you need to create

b. add content to the migration file.

Just copy the below code into your migration file. This creates the necessary table that is required to use the acts_as_fannable plugin.

 def self.up
    create_table “fans”, :force => true do |t|
      t.column “fannable_id”, :integer, :default => 0, :null => false
      t.column “fannable_type”, :string, :default => “”, :null => false
      t.column “user_id”, :integer, :default => 0, :null => false
      t.time_stamps
    end
 
    add_index “fans”, ["user_id"], :name => “fk_fans_user”
  end

  def self.down
    drop_table :fans
  end

c. run the rake command

rake db:migrate

This command shall create the fans table within your database. Ensure you already have created a database and updated your database.yml file.

II Usage of acts_as_fannable

a. Making a model acts_as_fannable.

Open your Model file e.g. User, Game,  Sport, Personality, Singer, Musician, Teacher, Student, etc.,

Add the acts_as_fannable element to it as shown below.

class Model < ActiveRecord::Base
   acts_as_fannable
end

This makes your model acts as fannable and now all the other users can become a fan of this model.

b. adding a fan to the model instance

In your controller, where you want to pick up the user to be a fan of the model, you can run an instance of the model, setup the user as fan and add them to the list. Note: you might have to get your user to login before they want to add themselves as fan. So your controller could look as

 model = Model.new
fan = Fan.new
fan.user_id = user.id (or self.current_user.id if acts_as_authenticated or restful authentication being used)
model.fans << fan
or
model.add_fan(fan)
Thats it you are ready to use the plugin.

 

Licensing?

We follow MIT License. Look out for the MIT-LICENSE file in the plugin folder

 

 

Active Scaffold is a great tool to provide a perfect AJAX based Scaffolding system for Rails Lovers. The flexibility that is build is in comparable. However as with any system not everything is possible, but yes for items where some of the activities is not possible active scaffold gives the actions to you to handle.

 

Some of them are as follows.

 

  1. You have a requirement to do a bulk upload of all the products that you have in your excel and do not want to create them one by one
  2. You have a requirement to run a calculation such as tax activity that you want to do only for each product after it is created. This calculation might not be part of the basic database fields that you have in the active scaffolds.

 

So for either of the above requirement you do not have a field in the active scaffold  / t able that is declared and they are not the normal active scaffold operations. This is something new. How do I handle it?

The solution is by using Active Scaffold Links (also called as action_links ) which helps you to connect to any action that you declare in your controller.

 

There are two types of active scaffold links, one is the table type and another is the record type. The Table type is best suited when you wan to use them for bulk upload activity i.e. that is one time activity and is not dependent on any particular object. And the Record type is used when you want to involve information of one particular object (product in this case)

 

How do we declare these elements. Within your active scaffold elements you have to declare the following items

 

config.action_links.add “bulk_upload”,:label=>“Bulk Upload”,:type=>:table

 

config.action_links.add “showproductcalculation”,:label=>“Product Calculation”,:type=>:record

 

 

The first link is of Table type. This link when added to active scaffold adds it just next to the Create / Search buttons. Which says that this information is irrespective of any particular object. However the second link being a record type is added just next to the edit / delete / show links for a particular product.

 

Looking at a sample active scaffold of this type we have the controller written as follows

 

active_scaffold :product do |config|

  config.label = “Product” # Display page name

  config.columns = [:name, :description, :product_image]

  config.action_links.add “bulk_upload”,:label=>“Bulk Upload”,:type=>:table

  config.action_links.add “showproductcalculation”,:label=>“Product Calculation”,:type=>:record

end

 

def bulk_upload

  # do all your Bulk Uploading stuff which is launches the bulk_upload.rhtml file

  # if available in the views/products folder

end

 

def showproductcalculation

  #do all your product calculation that you want to do for a particular product

   # The product id is available as params[:id]

   product = Product.find_by_id(params[:id])

   @displayproductinfo  = product.value *25/123;

end

 

Well that means bulk upload displays the bulk_upload action and subsequent bulk_upload.rhtml and the showproductcalculation is called.

 

The difference in the table type and record type is that in record type you have the pointer to the selected product through params[:id] which is not available in case of table type.

 

That’s what it is… using links in active scaffold, If you want to make this part ajaxified, you can always put your ajax code and make them work.

 

About Author: Ganesh Mohan is a Senior Developer working for Heurion Consulting Pvt Ltd, Bangalore, India, Providing solutions in Ruby on Rails and Microsoft Technologies. Though he has quite acquainted with both the technologies and always in a position to suggest which platform / technology is good enough for what kind of application to be developed. Ganesh has a computer science degree from Visvesvaraya Technical University, Karnataka

 

 

About Heurion Consulting: Heurion Consulting is an organization based in Stoke-on-Trent, UK and Bangalore, India providing solutions using Ruby on Rails technologies. We help organizations build websites to allow them sell their products, or help a group / team  / individual to recognize a pain area or build an idea that they want to evolve. Heurion Consulting have supported various Entrepreneurs realizing their dreams. For more details contact info@heurionconsulting.com and our website is www.heurionconsulting.com

 

In all our blogs we have all spoken about integrating some thing or the other… and also we have spoke about setting up text_areas, text_fields, etc., as part of our string database fields. However if you wanted some information which had to have rich text then, there is no support from the Active Scaffold end.

 

Whenever a rich text creation comes into mind, the first thing that we think about using a rich text editor (WYSIWYG) Editor which you would like to integrate with your text box to make it a rich text and provide all the styling features.

 

From experience we know that the Tiny MCE is the best and well known Rich Text Editor which is used in the internet world to implement Rich text…however tiny mce fails when it comes to using it within active scaffold… The reason is that active scaffold is a complete ajax application and for some reason it has failed to work. We also tried using the tinymce patch to make it work, but unfortunately it was not possible.

 

To our rescue came in the FCK Editor Plugin. By using this plugin we can ensure active scaffold textfields can be made rich text and get all the features that we get in tiny mce if not more. Also FCK Editor seems to be a much robust and better WYSIWYG editor which is being used by the Rails world.

 

Assuming FCK Editor Plugin is installed in your application. All you need is to change the details in the helper file. Since FCK Editor is a UI feature, you don’t have to do any change in the controller. In our example we have taken up the description field of the category class (Refer to our previous active scaffold posts) to which we need to provide rich text information.

 

In Category_Helper.rb we need to add the following code

 

#description field is shown in FCK editor format

def description_form_column(record, input_name)

 fckeditor_textarea( :record, :description, :toolbarSet => ‘Simple’, :name=> input_name, :width => “800px”, :height => “200px” )

end

 

#description text is displayed in rich format

def description_column(record)

 sanitize(record.description)

end

 

 

Thats it, You should be able to view the FCK editor in your active scaffold. However there is one issue, FCKEditor shall replace your description field and add its own description text area which provides the rich text information. Hence forth whatever you type in the rich text box is not actually available as the Value field of the basic description text field (which has been overwritten by FCKEditor). So while storing the contents of the description field to the database, the contents are not available to be stored. In order to solve this problem we need to add a small glitch into our code.

 

For this copy the “_create_form.rhtml” & “_update_form.rhtml” from ..\vendor\plugins\active_scaffold\frontends\default\views to Views/Category folder and edit them as follows

 

In  _create_form.rhtml you need to replace the submit button to have FCKEditor information as below

 

Instead of <%= submit_tag as_(‘Create’), :class => “submit” %>

 

we add following code

<input type=“submit” value=“Create” class=“submit”

onClick=“var oEditor = FCKeditorAPI.GetInstance(‘record_<%=@record.id%>_<%=’description’%>_editor’);

document.getElementById(‘record_<%=@record.id%>_<%=’description’%>_editor’).value = oEditor.GetXHTML();” />

 

The above code provides the mechanism to get the HTML content of the FCKEditor Record and place them in the value field as when we use the FCKEditor above the normal description text_field, it over rides the text field and placed its own rich text field. Since FCKEditor now transfers the content to the value field, this information will be available when the create / update actions of the controller is run.

 

You need to do the same in the _update_form.rhtml to get the fckeditor html content into the value field.

 

Once the glitch is added, your FCKEditor should work fine with active scaffold.

 

 

 

About Author: Ganesh Mohan is a Senior Developer working for Heurion Consulting Pvt Ltd, Bangalore, India, Providing solutions in Ruby on Rails and Microsoft Technologies. Though he has quite acquainted with both the technologies and always in a position to suggest which platform / technology is good enough for what kind of application to be developed. Ganesh has a computer science degree from Visvesvaraya Technical University, Karnataka

 

 

About Heurion Consulting: Heurion Consulting is an organization based in Stoke-on-Trent, UK and Bangalore, India providing solutions using Ruby on Rails technologies. We help organizations build websites to allow them sell their products, or help a group / team  / individual to recognize a pain area or build an idea that they want to evolve. Heurion Consulting have supported various Entrepreneurs realizing their dreams. For more details contact info@heurionconsulting.com and our website is www.heurionconsulting.com

 

Though Active Scaffold is a plugin which is used for ajax activities, for some cases where we want to upload images / files as part of our object, active scaffold fails as the basic file field will not work correctly with active scaffold. The reason is active scaffold is an ajax based system and file field is a non ajax based system…. However to the rescue comes in the File Column Plugin in Active Scaffold. There is a hook available that can be implemented to ensure file column works perfectly well with the active scaffold. The details are as follows

 

Requirements

  1. Active Scaffold Plugin is installed
  2. File Column Plugin is installed

 

Continuing from my previous active scaffold articles, I derive the problem of the products to show a image as part of the product activities. So the active scaffold I re-write would be as below

 

active_scaffold :product do |config|

    config.label = “Product Page”

    config.columns = [:product_name, :product_description, :product_image]

    config.create.multipart = true

    config.update.multipart = true

    config.columns[:product_image].label = “Product Image”

end

 

what I do here is just add a field :product_image which stores the file path of the image that is updated. However just adding the product image shall not do the job, like with other fields we have to override the product_image column and form_column methods in the helper methods to use file column plugin field.

 

So in our Product_Helper.rb we add  the below code

 

The below code is called by the create and edit actions which shows the user a file column filed to allow upload of the image for a particular row.

 

def product_image_form_column(record, input_name)

 file_column_field ‘record’, :product_image

end

 

 

The below code is called during the list and show actions to display the image that is associated to the product.

 

def product_image_column(record)

  image_tag url_for_file_column(record, product_image) if record.product_image

end

 

Hurray, my work is done the active scaffold now understands the file column. However there is still one question how does the active scaffold know that the product image is a type of file column…. Well all we need to do is one small modification in the Product.rb  (model file)

 

file_column :product_image

 

Finally done your active scaffold has been integrated with the File column. Which means there is a non ajax activity (file upload) with in an ajax activity (active scaffold).

 

That’s it enjoy coding….

 

 

About Author: Ganesh Mohan is a Senior Developer working for Heurion Consulting Pvt Ltd, Bangalore, India, Providing solutions in Ruby on Rails and Microsoft Technologies. Though he has quite acquainted with both the technologies and always in a position to suggest which platform / technology is good enough for what kind of application to be developed. Ganesh has a computer science degree from Visvesvaraya Technical University, Karnataka

 

 

About Heurion Consulting: Heurion Consulting is an organization based in Stoke-on-Trent, UK and Bangalore, India providing solutions using Ruby on Rails technologies. We help organizations build websites to allow them sell their products, or help a group / team  / individual to recognize a pain area or build an idea that they want to evolve. Heurion Consulting have supported various Entrepreneurs realizing their dreams. For more details contact info@heurionconsulting.com and our website is www.heurionconsulting.com

 

 

 

 

 

 

 

 

 

 

You have a problem that is you see a button Search next to Create and you dont know how to make use of it…Integrating Search in Active Scaffold is very easy.

 

In controller we need to write the following code to make it work:

Considering the category we have

 

active_scaffold :category do |config|

  config.label = “Category” # Display page name

  config.columns = [:name, :rank, :description, :products]    

  config.columns[:name].label = “Some Name”

  update.columns.exclude :rank # exclude rank column during edit

  # Search the list by name

  config.columns[:name].search_sql = “name”    

  config.search.columns << :name

  # Search the list by product name

  config.columns[:products].search_sql = “products.name”    

  config.search.columns << :products

 

end

 

What active scaffold does is that when ever you use the search with a keyword, it will search the category name and the product name for a particular keyword and returns the resulting categories

 

Simple isn’t it….

 

About Author: Ganesh Mohan is a Senior Developer working for Heurion Consulting Pvt Ltd, Bangalore, India, Providing solutions in Ruby on Rails and Microsoft Technologies. Though he has quite acquainted with both the technologies and always in a position to suggest which platform / technology is good enough for what kind of application to be developed. Ganesh has a computer science degree from Visvesvaraya Technical University, Karnataka

 

 

About Heurion Consulting: Heurion Consulting is an organization based in Stoke-on-Trent, UK and Bangalore, India providing solutions using Ruby on Rails technologies. We help organizations build websites to allow them sell their products, or help a group / team  / individual to recognize a pain area or build an idea that they want to evolve. Heurion Consulting have supported various Entrepreneurs realizing their dreams. For more details contact info@heurionconsulting.com and our website is www.heurionconsulting.com

 

 

Welcome to my yet another article on Active Scaffold. This time I am going to explain how to relate 2 tables within each other.

 

Let us assume you have a table category ( same name from my first article on active scaffold ) to which you want to associate products. So basically we have 2 Models Category (table name as categories) and Product (table name as products) which have a relationship bound as category :has_many => products and product :belongs_to => category. So basically a product can be associated to only one category.

 

There are two ways of building this

 

  1. Create a Category and with in it create a product
  2. Create a product and have a Dropdown for category to select while create / edit

 

Though it is very simple to do the latter i.e. creating a product and having a dropdown for category to select while create / edit, but the Former is much difficult. However in Active Scaffold it is much simpler. All you have to do is to associate the relationships and provide a relationship linking.

 

Coming back to my category controller (refer to my first article on active_scaffold), I now re-write it as

 

active_scaffold :category do |config|

  config.label = “Category” # Display page name

  config.columns = [:name, :rank, :description, :products]

  config.columns[:name].label = “Some Name” # customize column name

  update.columns.exclude :rank # exclude rank column during edit

  list.columns.exclude :description #exclude description column in list

  #this is a extra link which is applicable for every row if type record and if type is table then it is for all records

  config.nested.add_link “Add Products”, [:products]

end

 

All this says that to the existing system is that add a link along with create edit delete by name as Add Products and when it is clicked show all the products (as active scaffold) associated to that particular category.

 

Nested is a way of adding a table within a table and is used in case of displaying parent-child relationship. In this case the Category has a nested relationship with products table.

 

This doesnot finish it all. We still need to code what needs to happen when you click on the Add Products link. For that you need to generate a product controller and have a product model and table generated. In this case let us assume that the product table have the following fields

 

  • Product Name
  • Product Description
  • Category ID

 

Though here what we actually need is the product name and description, we need category_id field to establish a contact with it’s parent category table.

 

active_scaffold :product do |config|

  config.label = “Product Page” # Display page name

  # Category_id not needed by default it will take while adding

  config.columns = [:product_name, :product_description]

  config.columns[:product_name].label = “Product Name”

  list.columns.exclude :product_description

end

 

That’s it, now run your Now in your page you can

 

  1. Add / Edit / Delete Categories as you did in my first article
  2. Click on the Add Products and you see a nested table displayed where you can add / edit / delete products which are associated to that particular category.

 

Cool isn’t it? Look out for more information on active scaffold.

 

About Author: Ganesh Mohan is a Senior Developer working for Heurion Consulting Pvt Ltd, Bangalore, India, Providing solutions in Ruby on Rails and Microsoft Technologies. Though he has quite acquainted with both the technologies and always in a position to suggest which platform / technology is good enough for what kind of application to be developed. Ganesh has a computer science degree from Visvesvaraya Technical University, Karnataka

 

 

About Heurion Consulting: Heurion Consulting is an organization based in Stoke-on-Trent, UK and Bangalore, India providing solutions using Ruby on Rails technologies. We help organizations build websites to allow them sell their products, or help a group / team  / individual to recognize a pain area or build an idea that they want to evolve. Heurion Consulting have supported various Entrepreneurs realizing their dreams. For more details contact info@heurionconsulting.com and our website is www.heurionconsulting.com

 

Acivescaffold is a plugin which makes the life easier for many programmers and provides Ajaxified implementation. Active scaffold can also be called as the next generation component which replace ajax_scaffold plugin. It comes as a plugin which can be downloaded and installed.

 

To install active_scaffold plugin all you just need to do is

 

> ./script/plugin install active_scaffold

 

Now that we have installed the plugin, lets try to do something with it. The Goal is to create a CRUD for a model / table name Category / categories where we would like to create / edit / delete all the categories that can be used in the application.

 

Lets assume the table has the following fields

  • Name
  • Rank
  • Description
  • Disable status

 

So what do we do now?

 

Create a controller called categories ( name doesn’t matter) as

 

> ./script/generate controller category

 

This script generates a category_controller.rb, category_helper.rb and categories folder within /app/views. The views are not of importance as we don’t need them for this example.

 

Now in controller we need to write the following code:

 

active_scaffold :category do |config|

  config.label = “Category” # Display page name

  config.columns = [:name, :rank, :description, :disabled] # all fields are taken

  config.columns[:name].label = “Some Name” # customize column name

  update.columns.exclude :rank # exclude rank column during edit

  list.columns.exclude :description #exclude description column in list

end

 

 

What the above section does is

 

  1. Tells active_scaffold that the table name is categories (i.e. plural of category)
  2. Shows the Label in the top bar as Category
  3. Identifies the fields name, rank, description, disabled that can be controlled through active_scaffold
  4. Where ever name is used, it is replaced by Some Name i.e. in the list, create and update pages / forms
  5. Eliminate rank to be updated while edit is in progress
  6. Hide description in the List ( show only in Show page)

 

Once this is done, most of your work is actually complete. You run the server and go to the categories controller i.e. http://localhost:3000/category and you should be able to start using it.

 

However the items that you use to create and edit is actually coming in from the plugin and always the information is text field for fields with varchar and text declaration and dropdown for boolean fields (the drop down always contains True or False)

 

However if I want to override these implementation all I need to do is do some minimal modifications in the helper file.

 

In Category_helper.rb for each field(column) there are 2 methods that is declared. One as XXX_form_column and XXX_column.

 

XXX_form_column is always used when you want to over-ride the way you want to display the field information in the forms that is used by the create / edit process and XXX_column is always used when you want to over-ride the way you want to display  need to write the following code to display the field in case of list and show. Just as an example follow below

 

# Textarea to enter the description

def description_form_column(record,input_name)

  textarea :record, :name, :name=> input_name

end 

 

# Dropdown to select rank

def rank_form_column(record,input_name)

  select(:record,:pricing,[1,2,3,4,5,6,7,8,9,10],:name=> input_name)

end

 

# Label to display rank

def rank_column(record)

  output = “”

  record.rank.each do

      output += “*”

  end

  output

end  

 

In the above example you see that we have modified only the description and the rank fields. That means the Name and Disabled fields shall still use the basic active_scaffold’s implementation. Also if you see that we have overridden the description_form_column only and not description_column as we wish only to handle the case of description to use a text-area while creating / editing a category.

 

However incase of Rank, we have overridden both type as we feel that user needs to have a dropdown where he select the rank and also while showing to the user, instead of showing the number we want to override by showing the number of stars to it.

 

That’s it and code will work fine. No rhtml code has been used here. Stop by and view my other articles on active_scaffold… enjoy coding !!!

 

About Author: Ganesh Mohan is a Senior Developer working for Heurion Consulting Pvt Ltd, Bangalore, India, Providing solutions in Ruby on Rails and Microsoft Technologies. Though he has quite acquainted with both the technologies and always in a position to suggest which platform / technology is good enough for what kind of application to be developed. Ganesh has a computer science degree from Visvesvaraya Technical University, Karnataka

 

 

About Heurion Consulting: Heurion Consulting is an organization based in Stoke-on-Trent, UK and Bangalore, India providing solutions using Ruby on Rails technologies. We help organizations build websites to allow them sell their products, or help a group / team  / individual to recognize a pain area or build an idea that they want to evolve. Heurion Consulting have supported various Entrepreneurs realizing their dreams. For more details contact info@heurionconsulting.com and our website is www.heurionconsulting.com

 

 

 

 

 

Every one in the Ruby / Rails world knows and implements different payment methodologies for their E-commerce shopping cart. We understand people know much about how to integrate with Paypal, Authorize.net…blah blah blah… however the biggest issue with all these payment gateways is that the customers have to be associated with multiple websites i.e. If I want to buy something from a cart which associates to Paypal gateway, I need to have an account. So if that is the case then for every different Ecommerce payment gateway I need to have a separate account and I need to remember the credentials. Also many times if I want to implement offline payments such as money orders or cheque, etc., we don’t have any implementation that could take care of this system.

 

However many time I wished that it would be good that these shopping companies support multiple payment gateways and also multiple methods which are country oriented. E.g. Paypal is not an acceptable method in India, where as it is a Hit in US… Same way In France JCB is well known and in UK, Diners club, switch, maestro cards are well known. So I always believe that I should be allowed to pick up only the ones I need to make the payments as most of the time I shall be associated to one of them rather than getting myself associated to every one and forget at the end of the day where what transaction took place.

 

Thankfully to my support came in Bibit, a payment service of Royal Bank of Scotland (RBS) which supports almost all the payment gateways available and provides you information of gateways based on the country of the shopper. And to my advantage, I was supposed to write a code for a shopping cart to which it supported. Bibit is very much well known in Europe. Bibit also support Multi-Lingual

 

Before I start telling you how to implement bibit, a small introduction about BIBIT

 

“The Bibit Redirect, or Select, service model is an integration method to the Bibit Payment Service suited for Internet shop environments, call centers or reservation centers, and multi-channel sales situations. It allows for real-time processing of payments and ensures a maximum number of up-to-date payment methods. The Redirect model is secure, provides Bibit with required information to perform active fraud risk assessment, and is the fastest way to get up and running with on-line payments.” – As available in bibit website.

 

More details can be found in http://www.bibit.com . Also this post picks up much of the information from the bibit document and has been modified to suit Ruby on Rails users. The complete documentation irrespective of technology can be found in http://www.bibit.com/support/kb/pdf/BibitM03_Redirect1.3.pdf

 

What bibit does is, it provides a standard methodology to the shopping cart websites who can register with Bibit and then run their code with bibit. Once the shopping websites provide bibit some information the control is transferred to Bibit and after completion just like paypal, you can take back the control.  So actually the shopping Cart websites integrate their systems with bibit and bibit provides the customers of the shopping cart websites with various predefined payment gateways based on the country and languages.

 

Now we know what Bibit is, Lets to see how we can integrate bibit to our shopping carts.

Bibit provides an exclusive method called XML Order Creation which can be utilized to send information to bibit’s website as a secured channel and they handle the rest. The data is sent as an XML with some key elements such as description, amount, orderContent, paymentMethodMask and shopper.

 

Some of the Elements of this XML are as follows

 

  1. Document Type Declarations

 

As with any XML declaration we need to declare bibit as well to use the standards payment service dtd as follows

      

<?xml version=”1.0″?>

<!DOCTYPE paymentService PUBLIC “-//Bibit//DTD Bibit PaymentService v1//EN”

                                “http://dtd.bibit.com/paymentService_v1.dtd”>

 

  1. Merchant Information

 

This is the information that the shopping cart have to provide to bibit in order to authorize the input XML. The main information required is the merchant code.

 

<paymentService version=”1.4″ merchantCode=”MYMERCHANTCODE”>

  <submit>

</submit>

</paymentService>

 

The XML requires only the Merchant code, however in order to send the xml to the bibit website we need the merchant code as login and the xml password to send this XML. This is more explained in the Http Connectivity section

 

  1. Order Creation Details

 

While creating an order we have to follow few significant methods so that Bibit understands the order that has been sent. Some of them are

 

  1.  
    1. Order Description – Requires Order Code, Description, Order value, Currency in which order is being placed and the decimal place. The below is a sample example of an order. The Order Code has to be very much unique from bibit’s perspective and hence it is advisable to create the ordercode with a Salt of your’s and a number

<order orderCode=”T0211011″>

          <description>Some description of your product</description>

          <amount value=”2600″ currencyCode=”USD” exponent=”2″/>

         

</order>

 

  1.  
    1. Order Content – Has the complete details of the order and its line items. These details are wrapped inside a CDATA to allow bibit to confirm / show the user the order details. This is something like giving the details of what you would ideally put in a Confirm page before you place the order.

<orderContent>

  <![CDATA[content here]]>

</orderContent>

 

Some of the information that is generally part of order content are order code, line items, item price, total amount, shipping and billing addresses, merchant contact details, etc., For more information you can refer to bibit’s documentation.

 

  1.  
    1. Selecting Payment Gateways – In bibit, you can select which all payment gateways that you can allow to your client to login and support.

 

<paymentMethodMask>

    <include code=”ALL”/>

     <include code=”VISA-SSL”/>

     <exclude code=”AMEX-SSL”/>

</paymentMethodMask>

 

  1.  
    1. Email address – Finally we need to give the shopper’s email address as follows

<shopper>

          <shopperEmailAddress>shopper@myshopper.com</shopperEmailAddress>

</shopper>

 

  1. XML Validation

 

Finally it is a good practice to have a XML validation done on your xml. Bibit is quite strict about xml format and the transaction might fail for this activity.

 

So once you have the XML ready, it should look as below

 

<?xml version=”1.0″?>

<!DOCTYPE paymentService PUBLIC “-//Bibit/DTD Bibit PaymentService v1//EN”

                                 “http://dtd.bibit.com/paymentService_v1.dtd”>

<paymentService version=”1.4″ merchantCode=”MYMERCHANT”>

  <submit>

    <order orderCode=”T0211011″>

      <description>20 tulip bulbs from MYMERCHANT Webshops</description>

      <amount value=”2600″ currencyCode=”EUR” exponent=”2″/>

      <orderContent>

        <![CDATA[

        <center><table>

        <tr><td bgcolor="#ffff00">Your Internet Order:</td><td colspan="2"

        bgcolor="#ffff00" align="right">T0211011</td></tr>

        <tr><td bgcolor="#ffff00">Description:</td><td>20 Tulip bulbs</td><td

        align="right">1,00</td></tr>

        <tr><td colspan="2">Subtotal:</td><td align="right">20,00</td></tr>

        <tr><td colspan="2">VAT: 15%</td><td align="right">3,00</td></tr>

        <tr><td colspan="2">Shipping and Handling:</td><td align="right">3,00</td></tr>

        <tr><td colspan="2" bgcolor="#c0c0c0">Total cost:</td><td bgcolor="#c0c0c0"

        align="right">Euro 26,00</td></tr>

        <tr><td colspan="3">&nbsp;</td></tr>

        <tr><td bgcolor="#ffff00" colspan="3">Your billing address:</td></tr>

        <tr><td colspan="3">Mr. J. Shopper,<br>11 Shopperstreet,<br>1234

        Shoppercity,<br>Netherlands</td></tr>

        <tr><td colspan="3">&nbsp;</td></tr>

        <tr><td bgcolor="#ffff00" colspan="3">Your shipping address:</td></tr>

        <tr><td colspan="3">Mr.J. Shopper,<br>11 Shopperstreet,<br>1234

        Shoppercity,<br>Netherlands</td></tr>

        <tr><td colspan="3">&nbsp;</td></tr>

        <tr><td bgcolor="#ffff00" colspan="3">Our contact information:</td></tr>

        <tr><td colspan="3">MYMERCHANT Webshops International,<br>461 Merchant

        Street,<br>1255 Merchanttown,<br>Netherlands

        <br><br>mymerchant@webshops.int<br>(111) 1235 456</td></tr>

        <tr><td colspan="3">&nbsp;</td></tr>

        <tr><td bgcolor="#c0c0c0" colspan="3">Billing notice:</td></tr>

        <tr><td colspan="3">Your payment will be handled by Bibit Global Payments

        Services<br>This name may appear on your bank

        statement<br>http://www.bibit.com</td></tr>

        </table></center>

       ]]>

      </orderContent>

      <paymentMethodMask>

         <include code=”VISA-SSL”/>

        <include code=”AMEX-SSL”/>

        <include code=”ECMC-SSL”/>

      </paymentMethodMask>

      <shopper>

        <shopperEmailAddress>jshopper@myprovider.int</shopperEmailAddress>

      </shopper>

      <shippingAddress>

        <address>

           <firstName>John</firstName>

           <lastName>Shopper</lastName>

           <street>11 Shopperstreet</street>

           <postalCode>1234</postalCode>

           <city>Shoppercity</city>

           <countryCode>NL</countryCode>

           <telephoneNumber>0123456789</telephoneNumber>

        </address>

      </shippingAddress>

    </order>

  </submit>

</paymentService>

 

 

What Next, now lets do some Ruby coding to send this XML to bibit and do the processing. We shall utilize Net HTTP for the same. So in your controller i.e. where you have checkout processing being done you can add this code. I shall call my controller as CartController and the code shall be in cart_controller.rb

 

The first thing I require is to declare the required lib files. We need to declare http, https and uri classes. These are available as follows

 

 require ‘net/https’

 require ‘net/http’

 require ‘uri’

 

Once you have your declaration ready all you have to do is write the code in the make_payment  method

 

def make_payment

     #….write all the necessary code.to do necessary bibit payments
end

 

Lets understand one by one on what has to be filled with in the make_payment method

 

First get the XML ready

 

xml_string = %{xml as above}

 

It is better to putin the xml with in the %{} as the content becomes a well formatted xml. If we try to do it as quotes or double quotes, lots of escape sequences have to be used which is a pain. We found out sing %{} is the best method.

           

Once your XML is ready, Start posting the XML throught NET HTTP

 

All you need for this to work, is connection to the bibit service, your merchant code and the merchant password that you have declared in bibit.com using your login credentials.

 

  url = URI.parse(“https://secure.bibit.com/jsp/merchant/xml/paymentService.jsp”)

    @http=Net::HTTP.new(url.host, url.port)

    @http.use_ssl = true

    @http.start(){|http|

      req = Net::HTTP::Post.new(url.path)

      req.basic_auth MYMERCHANTCODE, MYXMLPASSWORD

      req['Content-Type'] = ‘text/xml’

      req.body = xml_string # as seen above

      response = http.request(req)

      response_xml = response.body

      return response_xml

    }

 

The URL you see is for the bibit’s test environment, All you have to do is to change the url to

 

Handling the Response

 

Once you send the XML to the bibit as above, bibit shall send you back an response XML which gives you some information about bibit accepting your order. All we have to do is to extract the order code and the re-direction information from response xml and re-direct our application to bibit to do the complete gateway process

 

 <?xml version=”1.0″?>

<!DOCTYPE paymentService PUBLIC “-//Bibit//DTD Bibit PaymentService v1//EN”

                                 “http://dtd.bibit.com/paymentService_v1.dtd”>

<paymentService merchantCode=”MYMERCHANTCODE” version=”1.4″>

  <reply>

    <orderStatus orderCode=”T0211011″>

      <reference id=”1234567″>

        https://secure-test.bibit.com/jsp/shopper/SelectPaymentMethod.jsp?orderKey=

MYMERCHANT^T0211011

      </reference>

    </orderStatus>

  </reply>

</paymentService>

 

All that is important in this xml is

 

Order URL – This is the URL that has to be redirected to allow bibit to complete the payments. The url in the xml is

 

https://secure.bibit.com/jsp/shopper/SelectPaymentMethod.jsp?orderKey=

MYMERCHANT^T0211011

 

 

Reference ID – This ID is more necessary for Future references or offline payments so that you know the status of the product. The reference ID in this xml response is

 

1234567

 

Order Code – This is the code that we generated before sending it to the bibit payment. This has to be unique and can be used to check in the database for order  placement. The order code in the xml response is

 

T0211011

 

In order to extract the information from the response xml we can use any parser such as ReXML parser / Atom Parser / CobraVsMongoose

 

Redirecting to Bibit

 

Once the URL has been acquired from the response XML, do a redirection to Bibit. Also you can do additional activities so that you can change the look and feel and information in the website.

 

a.      Redirecting URLs

 

Additionally you can customize the URL to send your success / failure / pending URLs to Bibit to redirect to your website so that you can handle the particular order status i.e. When the Bibit completes the payment and if you want them to redirect back to your website (similar to returnurl of paypal), you can provide them as encoded text along with the bibit url (available in the response xml). The procedure could be as follows

 

&successURL=CGI::escape(url_for(:controller=>”cart”, :action=>”success”)

       &pendingURL=CGI::escape(url_for(:controller=>”cart”, :action=>”pending”)

       &failureURL=CGI::escape(url_for(:controller=>”cart”, :action=>”failure”)

 

   https://secure.bibit.com/jsp/shopper/SelectPaymentMethod.jsp?orderKey=MYMERCHANTCODE^T0211011&successURL=http%3A%2F%2Fyour_domain.com%2Fcart%2Fsuccess&failureURL=http%3A%2F%2Fyour_domain.com%2Fcart%2Ffailure&pendingURL=http%3A%2F%2Fyour_domain.com%2Fcart%2Fpending

 

You are at your disposable to implement any of these. Bibit shall redirect to your URLs along with the order code so that you can handle if you want to convert the cart into an order or not. A sample Success URL that bibit creates is as follows

 

http://www.your_domain.com/cart/success?orderKey=MYADMINCODE^MYMERCHANTCODE^T0211010&paymentStatus=AUTHORISED&paymentAmount=2600&paymentCurrency=USD&mac=0083c47880f0533d773c350ee0d51cfc

 

 

b.      Setting Country and Language Codes

 

You can also set bibit the country code and the language code in order to allow bibit to show the payment methodologies for particular country and the bibit originating text based on language. This is again sent as part of the bibit url. Example URL is as follows
  https://secure.bibit.com/jsp/shopper/SelectPaymentMethod.jsp?orderKey=MYMERCHANTCODE^T0211011&country=GB&language=en

 

 

c.       Setting User Interface of Bibit Payment Service

 

You can also send font / body attributes to allow bibit show information in the way you want. E.g.

 

https://secure.bibit.com/jsp/shopper/SelectPaymentMethod.jsp?orderKey=MYMERCHANTCODE^T0211011&bodyAttr=bgcolor%3D%22black%22&fontAttr=face%3D%22arial%22+color%3D%22white%2

 

 

Hope this information helps you to start understanding and handle payments for your websites. We say three cheers to Bibit to help us solve a big problem.

 

Let us know your comments or if you need any support implementing Bibit Payments for your website.

 

About Author: Subhash Mohan is a Senior Developer working for Heurion Consulting Pvt Ltd, Bangalore, India, Providing solutions in Ruby on Rails. He has been an active participator in Bangalore Ruby User Groups and is quite acquinted with Ruby on Rails Programming.

 

 

About Heurion Consulting: Heurion Consulting is an organization based in Stoke-on-Trent, UK and Bangalore, India providing solutions using Ruby on Rails technologies. We help organizations build websites to allow them sell their products, or help a group / team  / individual to recognize a pain area or build an idea that they want to evolve. Heurion Consulting have supported various Entrepreneurs realizing their dreams. For more details contact info@heurionconsulting.com and our website is www.heurionconsulting.com

 

 

 

 

Next Page »