Mar 15

I’ve been depending upon an HTMLer to do the our HTML work.

Although he is good, it becomes apparent that we’re being too dependent, and the business just cant scale that way.

I believe everyone at Kiranatama should be empowered. I believe every engineers should be able to write Rails, write unit tests, do QA, deployment, caching, and also write HTML and CSS.

And so Kiranatama decides to train every engineers on HTML and CSS. Materials will come from Bulletproof Web Design.

This way, business can scale, and the skillset of our engineers improve.

Mar 13

If you have a Rails application that needs to include models from another Rails application, oftentimes you will want to add features to those methods, but you cannot since you cannot touch the other Rails app’s codebase.

If this is the case, you can use class_eval, which Neeraj explains nicely.

For example, if you want to add an after_save to a class Example :

Example.class_eval do
after_save :somemethod

def somemethod
end
end

Note that you dont wanna put that code under vendor/plugins/ . Instead, put it under a place where it’s executed everytime.

Mar 1

I’m too busy. My biggest client has taken too much time out of me, and thus I have less and less time and energy to expand this RoR outsourcing business.

I used to do all the stuffs, from recruiting, training, project-managing, to refactoring code.

See, the problem is that there are several potential clients wanting engineers. We can give them engineers but without enough training, project-managing, and refactoring (QA), I’m just so worried we cant give the quality and productivity we strive for.

We are polishing our company everyday. We built our ‘How-to-Manage-for-Productivity’ doc, proper training procedure, and Ruby on Rails best practices and quality standard document. And, I’ve distributed the roles of training, QAing, etc to people in my company, and thus I’m hoping we can accept new clients in a faster rate!

Feb 4

I confess. I havent had time updating this blog.
One of the more interesting projects that we have been working on is developing a facebook application using Rails.

I cant tell you what is this application about yet (the client wont let me)
But it’s a very exciting car/race game application, sort of like Speed Racer, but much better!

In developing this application, there are several issues I want to share with readers…

1) We wanted to use Rails 2.0, but unfortunately rfacebook doesnt seem to be compatible yet.
As I need ActiveResource for the project, I use Rails 1.2.4 instead…

2) We wanted to customize the profile box depending whether the viewer is the profile owner or not, like in this liverail tutorial (which we follow, but pretty outdated). But unfortunately, I can no longer do that…

3) We use lots of javascripts, such as tooltips and redbox plugin, but doing them in FBML is impossible(?), so we decided to use iframe, which works as good.

4) But using iframe can mean an ugly vertical scrollbar. One way to get rid of the scrollbar is to have the app rendered as FBML, and then use fb:iframe (so that javascripts still work) with a longer height.

5) Yes, we can know whom the user just invites on facebook (so that we can reward them with points, for example). On the ‘action’ parameter of fb:request_form, that’s where facebook will POST to after it’s done. It will give us params[:ids] as an array of user_ids just invited by the user.

Jan 2

This is useful if you want to have a hash that contains values of your ‘development’ or ‘production’ configuration.

If it is after the Rails app started, we can just do:

config = Rails::Configuration.new
database = config.database_configuration[”production”]
(Now you have access to database[:password], etc)

Without Rails, we can do

file_handle = YAML.load(File.new(”path/to/database.yml”)
hashes = file_handle.each {|value| value.inspect}
(Now you have access to hashes[”production”])

Dec 28

There are times when we want to install a gem as a plugin (or to be more precise, freezing the gem), so that we dont need to worry about installing the gem on other servers that may host the app.

Or so that we can modify the gem to suit individual applications.
For example, if we want to run multiple database migrations to different databases within one rake task script, then we need to modify the rake gem. Since modifying gem is usually not possible, we need to install rake as a plugin then modify it from there.

Basically, use gemsonrails instructions. If set up correctly, you’ll then have vendor/gems/[somegemname] and vendor/plugins/gemsonrails .

But an easier way to freeze gems is on err.the_blog.

Dec 18

I figure it is much much better to just use a great third party application like Wordpress to blog, rather than trying to come up with our own blogging system.

So here it is, I’m now using Wordpress (on a different domain) to write blogs for the Kiranatama site.

By the way, the two blog previews on the Kiranatama’s home page are retrieved from the Wordpress database, by creating a WpPost model in the rails app.

This new site just needs to be skinned. We’ll get to that later, for now, at least I have a much better blogging experience :)

Dec 12

I bought the Paypal Rails Integration ebook by Benjamin Curtis here.

But upon running the sample application, I cannot get through the purchase step and always get the error “There was an error processing your payment: Security header is not valid”

After some playing-around, although in the PDF it says “The modified version of the plugin included with the sample application does have the signature support.”, it turns out that the application doesnt have signature support.

So simply use PEM file instead of signature, like this:

ActiveMerchant::Billing::PaypalGateway.pem_file = path/to/file.pem

And remove the :signature element from PAYPAL_API_CREDENTIALS.

Dec 3

How do we cache an ajax response in Rails, so that we dont need to do an ajax the next time ?

It’s the question I’m facing on building an application that is AJAX-heavy, and it’s becoming important for the application to be high-performance.

After some googling, I came across several stuff. One is this interesting article on setting ‘Expires’ header in the HTTP response.

But well, I dont really know how to implement that in Rails.

Anyway his book, High Performance Websites seems like a very good book to buy!

So to cache an ajax response, I use the solution on this site.

Here is a simpler version of that:


<script>
var cache = new Array;
function myscript(somevalue) {
var url = "ajax/function?someparam=somevalue";
if (cache[url]) {
eval(cache[url]);
} else {
new Ajax.Request(url, {asynchronous:true, evalScripts:true,
onComplete:function(request) {
if(request.status == 200) { cache[url] = request.responseText; }
}});
}
</script>

Nov 29

It took me many hours to find out why my sessions are often gone when using memcache session storage.

Then I remember, that I cannot simply store any objects to a memcache session storage!

In the older rails, we have to do:

model :cart

to store an object of class Cart.

In the newer rails, just replace ‘model’ with ‘require_dependency‘.

For more info, read this site under If you have an “uninitialized constant” error

« Previous Entries Next Entries »