11 Jan 2008

Rails-Tip : Use Capture to wrap a part of View in a variable

RubyonRails, rails, rails-tip posted by SUR

The view helper method capture provides this functionality to wrap a section of the view template in a variable and can be used multiple times in the view.

Usage :

Advantage:

If its needed to render a section of template code, we usually go with partials. Capture is specifically useful when partial is only going to be used in just one view template. As there will be this variable available throughout the template, we can use it as many times as needed instead of partial.

10 Dec 2007

Presented at BarCampDelhi3

Barcamp, Delhi, EC2, Event, RubyonRails, deployment, hosting, rails posted by Akhil Bansal

Yesterday, I attended third barcamp in delhi. I presented a session “Deploying rails application in EC2″. It was an amazing experience. We talked about EC2 and I have given a demo “How to deploy rails application on EC2″.

I personally didn’t like some sessions that are based on marketing. There were people from some hosting company and after every 2 mins they were saying “we are the best”. I think this should not happen in barcamp. As far as I know about barcamp, it is for sharing your experiences, Talking about new technology, but not for promoting your company.

I think that, at BarCamp there should be sessions on new things, not on the things that are popular and have similar other services.

There was a very good session by Jinesh Varia on Amazon Cloud Computing. He included Amazon’s simple storage system, and Amazon’s cloud computing(Ec2) in his presentation. He also helped me to answering people while the demo. He gave me a hint that very soon there will a news from Amazon that will surprise us.

I have uploaded my presentation slides on Slideshare.net:

Thanks to Impetus Noida for Hosting Barcamp for second time and Opera for Beer.

05 Nov 2007

Two best online API/Rails API

API, RubyonRails, ajax, rails, ruby posted by Akhil Bansal

Today I found two best API sites. One is http://www.gotapi.com.
This site provides APIs of almost all languages.

The other API site which is only focused on Rails is http://www.railsbrain.com/. I like this most. You can also download this API. It is AJAX based fast, useful.

26 Oct 2007

Single Table Inheritance validates_uniqueness_of Problem

RubyonRails, Technology, rails, ruby, web development posted by Akhil Bansal

Consider a case of STI where:

Now try following at console:

This will let you create three records in users table with same name, validates_uniqueness_of written in User class has no effect on it. validates_uniqueness_of automatically scoped with class names, that means it will not let you create two managers with same name or two customers with same name or two users with same name.

If you want uniqueness of an attribute in overall table, put the following code in some file in your lib dir and require that file in environment:

And then use validates_overall_uniqueness_of instead of validates_uniqueness_of.

13 Sep 2007

Running Rails Application on https with pound

RubyonRails, Technology, deployment, hosting, https, mongrel_cluster, pound, rails posted by Akhil Bansal

Hours ago, I posted about, “How to deploy rails application with pound as a Balancer”.

Lets run rails application on https with pound. For that your machine should have:

* Pound installed with ssl support
* Pound and mongrels running

Now, First of all we need a ssl certificate, that can be generate by issuing “openssl req -x509 -newkey rsa:1024 -keyout mydomain.pem -out mydomain.pem -days 365 -nodes” . Give all the information it asks. Now copy mydomain.pem to /etc/pound/ directory(I am assuming that your pound.cfg file resides in /etc/pound/). Now put the following code in pound configuration file(/etc/pound/pound.cfg):

I am assuming that your mongrels are running at ports 8000, 8001, 8002, apache running at 8080 and pound is listening ports 443 & 80.
Restart pound, and you are done. With this configuration all requests for dynamic content at port 443(https) will get redirected to mongrels and requests for static content will get redirected to apache.

You may want to check if the request is https or not before serving the content. That can be done by adding a before_filter (defined below) in application.rb :

By adding this method as before_filter in application.rb your application will check for https, if the request is not of type https it will redirect to an https request.

Next Page »« Previous Page