Archive for the ‘Ruby on Rails’ Category

RailsConf Europe 2006: Unobtrusive Ajax with Dan Webb

Friday, September 15th, 2006

(code and slides)
Dan Webb’s Unobtrusive Ajax With Rails talk proved so popular yesterday that it is being redone in the main hall during lunch today.

Unobtrusive Ajax (or JavaScript really) is all about removing all those inline onclick=”return myFunc(an_id)” bits of code from your HTML and into your JS. Separating behaviour and mark-up. Attaching behaviour to your class definitions e.g. class=”productbutton”.

At the very least this makes your pages smaller (think of a 1000 item list which has onclicks inline vs. attached via a class in a separate JS.)

At the most it is the idea of the class assigned to HTML elements.

A big theme is graceful degredation for when JS is not available.

A good point is around a href=”#” which semantically and functionally doesn’t make sense. I am an offender here but aim to change.

button_to is a little known Rails helper that generates a button in a form. This is for when you should be using buttons and not links e.g. for delete links. Remember, links should not have side effects (if for no other practical reason than avoiding pre-fetch technologies like the Google Toolbar that will wipe your records.)

To get started with UJS checkout the Rails plugin at ujs4rails.com.

A good talk and as Dan says, it isn’t rocket science. It has obvious benefits even if you don’t care about semantics. Hopefully Rails takes the ideas into the trunk.

RailsConf Europe 2006: Search with Rails

Friday, September 15th, 2006

(slides)

Now at the shopping.nouvelobs.com ecommerce talk which is a large news site in France. Speaker is Gwendal Rou, very French.

ModelSearch is an extension of find that allows something like this:

search = ProductSearch.new()
search.buyable = true
search.Find(:all)

The idea is that searching with multiple columns is not at the usual high-level in Rails. You have to use SQL.

ModelSearch is capable of; Televisions costing less than 300, sorted by price.

search = ProductSearch.new
search.keyword - 'television'
search.max_price = 300
search.sort = :price
search.find(:all)

That is quite handy. I assume ‘max_’ is dynamically added onto model members. i.e. I assume you could have min_price too. My assumption is nearly correct, you just need to set it up in the model a bit.

A further extension lets you pass the search object into the normal model find e.g. Product.find(:all, search.find_options)

ProductSearch is a class you subclass from ModelSearch and setup with various params. e.g. search_key :keyword, :search => :keyword, in => [:name, :description]

All nicely model based this. Buyable, from the first code, is a custom method in the ProductSearch model. It works well with a form, letting you just pass in properly named input fields.

ModelSearch is planned for release soon.

All in all a nice bit of code for real world problems.

RailsConf Europe 2006: Why not

Friday, September 15th, 2006

It has just been announced that RubyCentral and O’Reilly Media will be producing next years RailsConf Europe and it will be in Berlin. 3 day event, 1 day of workshops and 2 days of talks.

And now for Why.

We start with a love poem for Ruby. It’s erotic, passionate, beautiful and… red. Like a ruby. And foxes.

Splat (*) in Ruby is not only eye grabbing but useful. e.g. array.push *IO.read ‘list.txt’ and then a put will break on newline. Splat (*) seems to be an array tool. [*0] => [0].

Seems this talk is about useful tricks in Ruby. I think. Bit of an interesting talker, from philosophy to code and around to romance in a single sentence.

Some sandboxing tips. With lightning, sans foxes. His library seems to be a way for a module to interact with two separate Rails apps. It launches mongrel with your module and puts the loaded apps into sandboxes that you can access.

And that was Why.

RailsConf Europe 2006: JavaScript debug and test

Thursday, September 14th, 2006

(slides)
Thomas is the author of script.aculo.us so he knows a little bit about JavaScript.

Script.aculo.us has a unit testing framework plugin for Rails (javascript_test plugin.) Outputs nice views. All the usual assertions and some simple benchmarking. Comes with a generator to get you up and running fast. Running multiple tests is done via rake and with multiple browsers, nice. No code coverage metrics. RJS not supported either.

He recommends good old FireBug for JS debugging. Hurrah. Venkman is still useful though thanks to its profiling feature he mentions. Webkit and Drosera for Safari and Microsoft Script Debugger for Internet Explorer.

A very boring speaker but he knows his stuff.

At the evening Q&A session now. You know we are amongst geeks when an evening session is fully attended. See you all in the morning.

RailsConf Europe 2006: Rails in the system

Thursday, September 14th, 2006

And into Jason Hoffman’s talk on systems administration and Rails. Deployment, hosting, power, databases etc.

Strongspace, a Rails app from Joyent, is at 60terabytes. Joyent does TextDrive remember so they know some things. BTW Jason is from Joyent.

Rails is just a small part of your entire system. You need a lot more than just a sorted Rails config to have a well served app.

Virtualisation is the real only way. Xen, VMWare (if you must) or Solaris Zones.

Jason is not enamoured with Linux; “If I could turn Linux into a clever way of saying ‘crashes everyday and doesn’t tell you why’, I would.”

WordPress, half a million users, uses DNS load balancing. Works pretty well.

Joyent chooses:
- Console is Lantronix
- Sun Fire AMD servers, T1000, X4100 etc.
- Opteron 285 and TI SPARC
- 2GB RAM
- Sen Fire X5400 storage
- 500GB SATA discs
- Solaris Nevada OS
- Gigabit with cat6 cables

DTrace is getting Ruby integration so you can write performance tests to find out what exactly is going wrong. DTrace is from Solaris and also ported to Mac OS X in Leopard via XRay in XCode.

Key concepts:
- virtualise
- seperate hardware comp. (db from procesing from storage)
- KISS
- stoichiometry (from chemistry, the practice of adding up. If you can’t just add on another server then you have problems.)
- config management and distributed control
- pool and split i.e. SOA
- Understand what is maximum to understand what should be happening vs. what is (potential)

I’ve asked Jason for the slides to this talk and will post them later.

Excellent talk from Jason.
- DNS and federation

RailsConf Europe 2006: Performance, RadRails and airlines

Thursday, September 14th, 2006

Three talks in and it is going fairly well. Soren Burkhart talk was billed as how they used Rails to revolutionise the airline industry. Untortunatley he spent too much time on the preliminaries and had to rush through the meat of his talk (the app and its development.) It looked interesting but we didn’t get into much detail. Might be worth contacting him directly to get some info.

James Cox’s talk on Rails performance and scaling (pdf) was pretty good. A chunk of my notes from it:

- columns => :select, pagination => :limit, :offset)
- @var ||= query
- MySQL is decent
- Memcache (doesn’t have to be on the same machine)
- mysql \s
- mysql - log slow queries - mysql_slow_queries
- nginx (russian but fast)
- mongrel for scaling even if it isn’t the fastest
- hostname lookup in apache2 bad

Matt Kent and Kyle Shank gave a demo of his RadRails IDE which seems to have come a long way from what I initially used. Auto-completion they want to do but apparently is a difficult feature.They are also working on porting TextMate Ruby snippets to RadRails. Certainly more featurefull than RIDE-ME at this stage. Autotest is a nifty way to run certain (or all) tests in the background on an interval or on save.

So far every talker has been young and inexperienced. Really smart but these aren’t slick conference speakers like you get at Java and Microsoft events. This is a good and bad thing. Good as you get low level info, bad because they can wander and be unprepared for the talk.

RailsConf Europe 2006: Start up

Thursday, September 14th, 2006

At RailsConf Europe 2006. Good turn out and location.

David’s keynote was very technical. He mentioned a revamping of the views (codenamed simply helpful, currently a plugin) and how ActiveResource probably won’t be in Rails 2.0.

Kathy Sierra’s talk was really good. All about passion and emotion in our products. Talk to the brain, not the mind i.e. go for the caveman in all of us rather than our abstracted logical sides. To a degree of course.

Pagination

Friday, September 1st, 2006

Kevin Clark’s Things You Shouldn’t Be Doing In Rails article is causing some consternation in the Railsosphere. Particulary the pagination comment:

I haven’t used pagination in my last 15 projects. The pagination code is ugly. Ugly ugly.

There are two parts to his comment. The first is that the implementation of pagination that everyone first gets with Rails is poorly done. It is not scalable and is inflexible.

“So what do we use instead?” is being asked by many and there has been no real answer beyond the obvious answer; write your own pagination code that fits your application.

The second part of the pagination comment though is more interesting. Brian Hogan comments:

Pagination of “next / previous” is pretty useless on large data sets anyway. Alphabet bars or searches are much better approaches for filtering data in my opinion and they’re easy to implement.

That is very interesting. Yes, there will be times that pagination is the only logical way of cutting datasets up but they are rare, very rare.

But everyone uses pagination! Google does!

That is because it is easy. Maybe not easy to implement but easy to conceptualise. It is dead easy to say “List the data in chronological order in pages of 20 records.”

Instead you should be thinking hard about the data you are presenting. If your data is timely then page by logical date ranges (hour, day, month, range etc.) and not just chronological + page sets.

If your slicing results in too long a list to display on one page then you need to slice it better, not just stick in page numbers.

Google is a good example. When I search and don’t find the result I want on the first page I don’t go to page 2. I research. I refine my search.

Rails gem files

Thursday, August 17th, 2006

If you ever need to install Ruby on Rails 1.1.6 then here is the minimal list of gems you need:

Use gem install on them.

RailsConf Europe 2006

Wednesday, August 16th, 2006

I just booked my place at the European Ruby on Rails conference being held on the 14th and 15th of September in London. If you are going drop me a line.