Globalize2 and Thinking Sphinx
If you are trying to integrate Thinking Sphinx with models using Globalize2 for translations, here is what worked for me. Many thanks to Zach Inglis and Pat Allan for their help.
My Article class uses Globalize2 to translate ‘title’ attribute in two locales (:en and :fr). Globalize2 creates an association named ‘translations’ for the table article_translations.
The solution is to set up one index per locale. As you see, ‘article_en’ automatically creates ‘article_en_core’ and ‘article_en_delta’ index if you use delta indexing.
To limit your search within a particular locale, pass on the :index option.
For ex:
MooTools: Class Methods and Inheritance
In my last project, I enjoyed scripting using mootools and started exploring it more deeply. One of my extensive use was to define UI elements’ functionality in classes and then create multiple instances for re-usability.
Mootools makes use of Javascript’s native prototype model for inheritance. To extend a base functionality into sub class, mootools provide ‘Extends’ method. However, if you have class methods in your base model, Extends is insufficient to get them into the sub classes. After some research, I managed to solve this by using Class Mutators and overriding the Mootools ‘Extends’ to take care of class methods inheritance.
First of all, we need to define a ClassMethods mutator. Mutators belong to a class, not to their instances and they are called only when we define a new Class.
Next, we need to redefine Mootools Extends mutator:
Check out the example below:
You can see the above code working here.
http://jsfiddle.net/rZvJE/11/
Continuous Authority and repeated transactions using SagePay Gateway
SagePay allows us to process repeated capture transactions against a successful payment authorization. You can get more information about the introduction and instructions for obtaining a Continuous Authority Internet Merchant Number here.
This example makes use of a forked version of ActiveMerchant and SagePay Simulator environment. Please refer to the previous article for setup instructions.
Setup:
Make sure to check ‘Continuous Authority’ in the simulator account settings.
Case 1: A non 3D Authorized Transaction
response.authorization shows a value simiar to:
00001;{E5AC4385-06F8-40DD-8486-22EFB23768AE};9030;03FQG5AJA6;authorization
Capture the Payment
Repeat the transaction using previous authorization reference.
Case 2: 3D Authorized transaction
Follow the steps 1-3 for 3D Secure Payment Transaction as shown in the previous article. You’ll notice that the authorization returned by a three_d_complete process is incomplete and it looks something like “;{FB448BBF-CB72-414A-B293-316004162EEB};6598;OUWEBUCWL3;three_d_complete”
Prepend the order_id used in step 1 to this authorization reference so that it matches following format:
three_d_auth_reference = “00003;{FB448BBF-CB72-414A-B293-316004162EEB};6598;OUWEBUCWL3;three_d_complete”
Where “00003″ is the order_id used for authorization in step 1.
Capture this 3D Authorized payment for the first time by calling:
This transaction can be repeated by using the previous successful authorization (three_d_auth_reference) with a new order_id.
Html to plain text using webrat and nokogiri
Here is a snippet to parse a given http response into plain text. Basically it removes html tags, css blocks, script tags and yield visible text elements as seen in browser.
Gives:
Using AutoComplete with ActiveScaffold forms
This is a quick guide to set up auto_complete text fields in forms rendered by ActiveScaffold plugin.
I am not a huge fan of ActiveScaffold, but found these steps worth publishing after doing this for one typical project requirement.
1. Models
2. Install ActiveScaffold and AutoComplete Plugins
3. Controller Configuration
This renders a drop down list for country field, instead of the default create/replace form. However, we need to render an auto completing text box for which we need to replace the form column.
4. Form column override
Next step is to override the form column. Create a file named _country_form_column.html.erb in app/views/cities folder.
The second option :method => :get is needed to avoid the InvalidAuthenticityToken error generated by the ajax post request.
5. Since the form now returns country[name] instead of record[country_id] in params, we need to assign country object before creating city record. The CitiesController finally looks like:


