Its all about Ruby On Rails
Posts tagged ruby
Two best online API/Rails API
Nov 5th
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.
Update: APIdoc is also very useful. You can get community help here.
Running Rails Application on https with pound
Sep 13th
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):
ListenHTTPS Address 0.0.0.0 Port 443 Cert "/etc/pound/mydomain.pem" # pass along https hint AddHeader "X-Forwarded-Proto: https" HeadRemove "X-Forwarded-Proto" Service URL "/(images|stylesheets|javascripts)/" BackEnd Address 127.0.0.1 Port 8080 End Session Type BASIC TTL 300 End End Service BackEnd Address 127.0.0.1 Port 8000 End BackEnd Address 127.0.0.1 Port 8001 End BackEnd Address 127.0.0.1 Port 8002 End End End
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 :
def confirm_ssl unless request.ssl? request.env["HTTPS"] = "on" redirect_to "/" return end end
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.
Acts_as_solr: Starting solr server on windows
Sep 13th
I was using acts_as_searchable for one of my project, which uses Hyperestraier in background. Yesterday I decided to use acts_as_solr which uses solr(based on Lucene Java search library). I did all written in its Manual/Readme, but when I issued
rake solr:start
to start the solr server, it threw a heart breaking “Bad file descriptor” error, although acts_as_solr was working fine on one of my colleague’s linux machine.
I started digging around this and found that there is an issue in rake task that starts the solr server. Actually the problem was this rake task uses ‘fork’ which is not available on windows, also it only handles ‘ECONNREFUSED’ exception which is actually “Connection Refused” error raised by ruby on linux. But in windown it throws ‘EBADF’ which is “Bad file descriptor” error raised by ruby on windows.
So below is the hack for that:
desc 'Starts Solr. on windows . Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.' task :start_win do begin n = Net::HTTP.new('localhost', SOLR_PORT) n.request_head('/').value rescue Net::HTTPServerException #responding puts "Port #{SOLR_PORT} in use" and return rescue Errno::EBADF #not responding Dir.chdir(SOLR_PATH) do exec "java -Dsolr.data.dir=solr/data/#{ENV['RAILS_ENV']} -Djetty.port=#{SOLR_PORT} -jar start.jar" sleep(5) puts "#{ENV['RAILS_ENV']} Solr started sucessfuly on #{SOLR_PORT}, pid: #{pid}." end end end
Just add this to vendor/plugins/acts_as_solr/lib/taks/solr.rake, and start solr server on windows by issuing
rake solr:start_win
Engine Yard: Best Hosting for rails applications
Mar 20th
Today I deployed my rails application to Engine Yard server. They have great configuration, ultimate cluster architecture(physical clusters then logical clusters). They have separate servers for SSH, email, web, app etc… . Servers are managed by top architects, I should say they are expert in rails application deployment.