Administrator Kiranatama Staff
Knowledge

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"])

Install gem as plugin  

28 Dec 2007
Administrator Kiranatama Staff
Knowledge

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.

Wordpress on Rails  

18 Dec 2007
Administrator Kiranatama Staff
Knowledge

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 :)
Administrator Kiranatama Staff
Knowledge

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.
Administrator Kiranatama Staff
Knowledge

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>