12 September 2008

Using the MootTools AutoCompleter with Rails 2.x

Rails 2.x has cross site request forging prevention feature. By defautl, all non-GET requests will be checked with a session token field to all forms.

As the MootTools AutoCompleter uses 'POST' requests by default, you will run into the following problem:

Processing TypusExtrasController#autocomplete_place (for 127.0.0.1 at 2008-09-12 13:02:30) [POST]
Session ID: BAh7DToMdXNlcl9pZGkEde1AOjoMY2l0eV9pZGkGOgljaXR5Ig5iYXJjZWxv
cHVzaQY=--d44a8439a97a5da236cea2f22dceb239456a3ed1
Parameters: {"action"=>"autocomplete_place", "value"=>"A", "controller"=>"typus_extras", "model"=>"places"}

ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/request_forgery_protection.rb:86:in `verify_authenticity_token'


The solution is add a parameter to the javascript of the Autocompleter so it uses 'GET' requests instead:


var completer = new Autocompleter.Ajax.Json(el, '/admin/places/autocomplete_place', {
minLength: 1,
ajaxOptions: {method: 'get'}
...

10 September 2008

Loquo.com sucks & Yahoo!Pipes rocks!

loquo.com is definitely the main ads service in Barcelona (Spain?) . If you want to find a flatshare (people willing to live in Barcelona can't afford to leave on their own or buy a property until the house market completes its explosion), something second hand, this is the place to go!

loquo.com sucks. I am not talking about its old school user interface ... At the end of the day, what's matter most in an 'ads' website is to find what you're looking for !!!

loquo does not have any kind of advanced search:

The image “http://lh4.ggpht.com/jeanmichel.garnier/SMefBJr8b1I/AAAAAAAABFg/dZmTpla4EWM/alquiler%20de%20habitaci%C3%B3n%20Barcelona%20%7C%20vivienda%20%7C%20Loquo%20Barcelona.png” cannot be displayed, because it contains errors.

You can't filter anything. Most of the ads specify "only girls", so if you're a guy you'll have to read these hundreds of "solo chicas" ads. You can't filter by area or anything in the description.

By contrast, London based and free service moveflat.com offers the most useful search filters "ever ever":

The image “http://lh6.ggpht.com/jeanmichel.garnier/SMefqgjo_oI/AAAAAAAABFo/fjg8q8DMqiw/London%20flatshare.png” cannot be displayed, because it contains errors.


Another problems is the repetition of ads. Adding an add is free so most people add their add many times to make sure they appear at the top of the search results. Loquo displays the results order by date of publishing and you can't change the order ...

Fortunately, Yahoo! pipes rocks and will help us to filter loquo search results using the RSS feeds. I have created a pipe you can tweak to adapt it to your needs. Here is an example of the output for 'a monitor OR pantalla OR LCD with price<= 150€:

The fact that loquo was bought by ebay and since then no major feature was added tends to comfort me in my opinion that innovation comes mainly from the small guys. The creators probably got some money and left ...

Once again, the contrast is huge with moveflat.com created by an amateur who does not make money of it and did it for the sake of doing things well and help other people ...

09 September 2008

has_many_polymorphs regression after the upgrade to Rails 2.1.1

vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/dependencies.rb:8: Dependencies is not a module (TypeError)

This is dued to a Rails 2.1.1 refactoring in the location of the ActiveSupport::Dependencies module.
Copy paste the following code to your /has_many_polymorphs/lib/has_many_polymorphs/dependencies.rb to fix the problem:


module ActiveSupport
module Dependencies

mattr_accessor :injection_graph
self.injection_graph = Hash.new([])

# Add a dependency for this target.
def inject_dependency(target, *requirements)
target, requirements = target.to_s, requirements.map(&:to_s)
injection_graph[target] = ((injection_graph[target] + requirements).uniq - [target])
requirements.each {|requirement| mark_for_unload requirement }
_logger_debug "injection graph: #{injection_graph.inspect}" if Dependencies.log_activity
end

# Make sure any dependent constants of the constants added by yield are reloaded.
def new_constants_in_with_injection(*descs, &block) # chain

if Dependencies.log_activity
_logger_debug "autoloaded constants: #{autoloaded_constants.inspect}"
_logger_debug "explicitly unloadable constants: #{explicitly_unloadable_constants.inspect}"
end

returning(new_constants_in_without_injection(*descs, &block)) do |found|
_logger_debug "new constants: #{found.inspect}" if Dependencies.log_activity and found.any?
found.each do |constant|
injection_graph[constant].each do |requirement|
requirement.constantize
_logger_debug "constantized #{requirement}" if Dependencies.log_activity
end
end
end
end
alias_method_chain :new_constants_in, :injection

end
end



I am using the plugin has_many_polymorphs to manage tags in languages. An event has a category which is in reality a tag we translate in 7 languages ...

I inherited this plugin from the previous developper and I am looking forward to replace it by acts_as_taggable_on_steroids !

08 September 2008

stack level too deep bug with Rails 2.1 & will_paginate plugin

To live on the cutting edge of open source web frameworks (like Rails) is sometimes dangerous. How many times you have been slowed by some kind of regressions just after an upgrade to the latest version of a dependency?

The problem I have solved today happened with Rails 2.1.1 and a "version" of the will_paginate plugin I installed in May 2008.

Here is an extract of the stacktrace so google can index the information which will help other people to solve this problem quicker than I did ;-)

SystemStackError: stack level too deep
vendor/plugins/will_paginate/lib/will_paginate/finder.rb:92:in `method_missing_without_paginate'
vendor/plugins/will_paginate/lib/will_paginate/finder.rb:93:in `method_missing'


Googling "Rails 2.1 acts_as_taggable"", I found in a german blog the solution:

As I also use the will_paginate plugin and there are known stack level too depp problems with the old version of it, I tried to change it for the “Mislav” version of will_paginate and it solved the problem!

will_paginate is now on github: http://github.com/mislav/will_paginate/

To conclude, we should always try to specify the version of the dependencies through Rails 2.1.x sytem or the more mature gemsintaller, which has a better spec coverage.

To solve the problem of plugins stability , I am dreaming about a Continuous Integration farm of CruiseControl.rb running different versions of Rails and testing with selenium-grid the plugins ...

This would increase a *lot* the productivity of the Rails community, the plugins which would pass the tests of the "Farm" could be stamped "enterprise" ;-)



04 September 2008

Do not host your sites in Piensa Solutions

September 2008: euro is very strong and dollar weak, which makes hosting of web sites very cheap in the US. Anyway, for Rails hosting, the offer is very limited in Europe ...

Even if the cost of the service is important, what's matter most for a web site hosting is the quality of of the service and especially the response time and skills of the help desk.

Let me tell a story about Piensa Solutions. Some I know had an important web site hosted by them, theychose them because they claim 33 000 customers with 150 000 hosted sites.

Because of a mistake of their billing departement, they decided to "stop" their server without any warning and they needed more than 2 hours to reply. This is the email they sent:

Piensa Solutions

Estimado cliente:

Te informamos que en estos momentos tu hosting se encuentras cortado por impago ya que tiene pendiente una factura asociada al servicio, la X****. En el momento en que se abone dicha factura, a lo largo del día se reactivarán los servicios de tu alojamiento.

Estamos a tu disposición para cualquier consulta o aclaración al respecto.

Un saludo,

--
Facturación - Piensa Solutions
facturacion@piensasolutions.com
www.piensasolutions.com

AVISO LEGAL
Este mensaje y sus ficheros adjuntos tienen carácter privado y confidencial y van dirigidos exclusivamente a sus destinatarios. Si ha recibido este mensaje por error, no debe revelarlo, copiarlo o distribuirlo en ningún sentido sin previo consentimiento por escrito de Piensa Solutions. Rogamos lo comunique al remitente y elimine dicho mensaje y cualquier documento adjunto que pudiera contener. De no hacerlo así puede vulnerar la legislación vigente.


Basicly, they say that:

"You did not pay a bill so we cut your service" ...

NO COMMENTS!!!!