Rails-Tip : Use Capture to wrap a part of View in a variable
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.
Two best online API/Rails API
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.
Single Table Inheritance validates_uniqueness_of Problem
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.
Running Rails Application on https with pound
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.

