Posts mit dem Label Rails werden angezeigt. Alle Posts anzeigen
Posts mit dem Label Rails werden angezeigt. Alle Posts anzeigen

Sonntag, Mai 17, 2009

No Login after upgrade to Rails 2.3?

It cost me some hours on a sunday afternoon. After I upgraded to Rails 2.3.2 the login didnt work anymore. I read the release notes and followed all the instructions for cookie based sessions, like renaming session_key to key in the session config hash but still no luck. Things got more confused because locally everything worked fine. To make it short the solution is really very simple but you dont read much about it: you need to upgrade passenger to the newest version.


gem install passenger

passenger-install-apache2-module


And dont forget to adjust your apache config with the new settings. These are generated by the installer so you can just copy them.

Sonntag, Januar 11, 2009

switching to passenger

Though I am working with passenger for a while now, I just had new projects which started from the scratch using passenger. This week I switched my first mongrel based rails app to passenger. The idea was using passengers GlobalQueue option to optimize overall perfomance. One of the major mongrel drawbacks is its port based queues. If you have long running requests all others in the queue for that port have to wait. Thats different if you have just one global queue which doesnt pass request to busy processes.

While this works well as expected there are some minor modifications in the request header because the proxy has gone. For instance the webapplication read the calling ip address with the HTTP_X_FORWARDED_FOR header info. This is empty now with passenger.

So instead of calling

request.env['HTTP_X_FORWARDED_FOR']

I had to use

request.env['REMOTE_ADDR']
which has just the same info, the calling IP.

Sonntag, September 21, 2008

620 Errors while testing with Google Geocoding

If you are using Googles Geocoding Api you might experience occasional problems with 620 errors, especially while testing. The reason for this is Google prohibits too many calls in a short period. But for most testcases geocoding is not an issue so you should disable it for these.

Fortunatly in Ruby its easy to override existing methods to mock them. I use the geokit plugin and with it this could be done by the following method:

def disable_geocoding
GeoKit::Geocoders::Geocoder.instance_eval do
def geocode(a)
res = GeoKit::GeoLoc.new
res.lat = 13.423007
res.lng = 52.534194
res.success = true
res
end
end
end



Include this in your testhelper and call disable_geocoding in your setup method.

Montag, April 28, 2008

Upgrade to rails2

Yeah, since last week palabea runs on rails2 on production. The actual refactoring was painless and even the production deploy had just minor bugs. There are tiny changes coming with the upgrade - like empty parameters are now blank and not nil - which fell through our test coverage. So a quick look over all your controllers is needed if you want to avoid surprises in production.

Donnerstag, April 03, 2008

Adding parameters to routes

Routes are definitly one of the black holes in rails development. Most of the time you are dealing with standard configurations. You have to learn them, but there are not too many options you have.
But last time I wanted something special: to add an parameter to a url if a special route is called. We have /videos and we have /videos?lecture=true. Both are videos, share the same table and model, but they are treated differently in the GUI. So I thought definining a new route /lectures would be nice. I should call the same methods as for /videos but with a special parameter added. There is no way to do it. But hey I thought thats Ruby. What about adding a block, or override a special method. Then I started digging into the code. ... Wow, thats hot stuff, where to start? Jamis Buck tried but I couldn't figure out where and how to place my hook.
Finally I resignated and added a before_filter to the controller which does a regexp check against the request_uri. This does also the job, but I added code to the controller which is part of the routes logic, so really I dont like the solution. But it works fine for now.