85
Ruby on Rails from the other side of the tracks Tom Armitage LRUG, August 8th

Ruby on Rails from the other side of the tracks

Embed Size (px)

DESCRIPTION

A 20-minute chat at the London Ruby User Group (from August 2006) about how to get client-side-developers, and even designers, involved in the process of making applications with Rails - helping them get involved in the templating process. It then diverges into a client-side perspective on Rails, looking in particular at issues around Javascript and Ajax, and XHTML testing. Because of its slide-heavy nature, it’s fairly self explanatory, but obviously you’ll miss out on some of the discussion around the talk (which was excellent).

Citation preview

Page 1: Ruby on Rails from the other side of the tracks

Ruby on Railsfrom the other side of the tracks

Tom ArmitageLRUG, August 8th

Page 2: Ruby on Rails from the other side of the tracks

aka

Page 3: Ruby on Rails from the other side of the tracks

“working with your design team”

Tom ArmitageLRUG, August 8th

Page 4: Ruby on Rails from the other side of the tracks

Who here makes stuff on the web? In

Rails, maybe?

Page 5: Ruby on Rails from the other side of the tracks

Who would say they were roughly

between “good” and “expert” at either Ruby or

Rails?

Page 6: Ruby on Rails from the other side of the tracks

You may be used to the following

screens. But. This is not the web:

Page 7: Ruby on Rails from the other side of the tracks
Page 8: Ruby on Rails from the other side of the tracks

nor is this:

Page 9: Ruby on Rails from the other side of the tracks
Page 10: Ruby on Rails from the other side of the tracks

nor is this:

Page 11: Ruby on Rails from the other side of the tracks
Page 12: Ruby on Rails from the other side of the tracks

(thank god)

Page 13: Ruby on Rails from the other side of the tracks

the Web is

Page 14: Ruby on Rails from the other side of the tracks
Page 15: Ruby on Rails from the other side of the tracks

HTML

Page 16: Ruby on Rails from the other side of the tracks

HTML

Page 17: Ruby on Rails from the other side of the tracks

XHTML

Page 18: Ruby on Rails from the other side of the tracks

CSS

Page 19: Ruby on Rails from the other side of the tracks

Who here would say they had expert-

level XHTML?

Page 20: Ruby on Rails from the other side of the tracks

Why the hell don’t you?

Page 21: Ruby on Rails from the other side of the tracks

It’s OK, we have people to do this for

us:

Page 22: Ruby on Rails from the other side of the tracks
Page 23: Ruby on Rails from the other side of the tracks

Designers!

Page 24: Ruby on Rails from the other side of the tracks

They will save us with their rounded corners and stock

photos!

Page 25: Ruby on Rails from the other side of the tracks

More to the point, some of them might

be good at that XHTML lark!

Page 26: Ruby on Rails from the other side of the tracks

Sometimes dedicated people (not “designers”) write markup - so

also talk to:

Page 27: Ruby on Rails from the other side of the tracks

Client-side developers

Markup monkeys

Page 28: Ruby on Rails from the other side of the tracks

Anyway...

Page 29: Ruby on Rails from the other side of the tracks

What to do with front-enders

Don’t assume you know better

Don’t outsource

Get them on board

Get them templating

Page 30: Ruby on Rails from the other side of the tracks

Why?Close the loop

Give them ownership

Let them do their job

Avoid mistakes

Page 31: Ruby on Rails from the other side of the tracks

Mistakes, you say?

Page 32: Ruby on Rails from the other side of the tracks

<ul class=’someclass’><li>An item</li><li>Another item</li><li>The third item</li>

</ul>

A list of items.

Page 33: Ruby on Rails from the other side of the tracks

<ul class=’someclass’>for item in @items<li><%= item.name=></li>end

</ul>

The developer immediate approach.

Page 34: Ruby on Rails from the other side of the tracks

<ul class=’someclass’></ul>

Whoops.

This is valid XHTML 1.0 strict, but it may also lead to positional/aesthetic issues.

Text

(It’s also bobbins, semantically.)

Page 35: Ruby on Rails from the other side of the tracks

<ul class=’someclass’>for item in @items<li><%= item.name=></li>end

</ul>

Let’s improve this...

Page 36: Ruby on Rails from the other side of the tracks

if @items.size > 0<ul class=’someclass’>for item in @items<li><%= item.name=></li>end

</ul>end

That’s better.

Page 37: Ruby on Rails from the other side of the tracks

if @items.size > 0<ul class=’someclass’>for item in @items<li><%= item.name=></li>end

</ul>else <p>You have no items</p>end

(Best).

Page 38: Ruby on Rails from the other side of the tracks

How?Get them into source control

If you explain it well enough, everyone loves version control

Collaborate on working wireframes

Answer their questions

Ask them questions

Intervene (eg with helpers)

Page 39: Ruby on Rails from the other side of the tracks

Some notes

Page 40: Ruby on Rails from the other side of the tracks

Javascript & AJAX

Page 41: Ruby on Rails from the other side of the tracks

AJAX is cool!

Page 42: Ruby on Rails from the other side of the tracks

Javascript is coming back into

fashion.

Page 43: Ruby on Rails from the other side of the tracks

(Who here would say they had expert level Javascript?)

Page 44: Ruby on Rails from the other side of the tracks

(Work on it - it’s going to come in

handy)

Page 45: Ruby on Rails from the other side of the tracks

Libraries make Javascript much

less of a PITA.

Page 46: Ruby on Rails from the other side of the tracks

Libraries are heavy

Page 47: Ruby on Rails from the other side of the tracks

Library weigh-in:

prototype.js - 56kb

effects.js - 34kb

controls.js - 29kb

dragdrop.js - 30kb

Page 48: Ruby on Rails from the other side of the tracks

The problems with Prototype

Scaffolding gives you bad habits:<%= javascript_include_tag :defaults %>

That’s 146kb on your page load

And it loads serially

Use what you need

You don’t even need Prototype for basic JavaScript

Page 49: Ruby on Rails from the other side of the tracks

Helpers and accessiblity

Page 50: Ruby on Rails from the other side of the tracks

Rails’ HTML helpers are pretty great

Page 51: Ruby on Rails from the other side of the tracks

Rails’ HTML helper are:Accessible!

Valid!

Powerful!

Page 52: Ruby on Rails from the other side of the tracks
Page 53: Ruby on Rails from the other side of the tracks

Rails’ Javascript helpers, on the other hand...

Page 54: Ruby on Rails from the other side of the tracks
Page 55: Ruby on Rails from the other side of the tracks

They work...

Page 56: Ruby on Rails from the other side of the tracks

...but not like they should.

Page 57: Ruby on Rails from the other side of the tracks

eg

Page 58: Ruby on Rails from the other side of the tracks

<a href=”#” onclick=”...”>

foo</a>

Page 59: Ruby on Rails from the other side of the tracks
Page 60: Ruby on Rails from the other side of the tracks

<a href=”/toggle-user”

class=”toggle-user”>foo</a>

Page 61: Ruby on Rails from the other side of the tracks
Page 62: Ruby on Rails from the other side of the tracks

Seriously, though:Javascript has thorny accessibility issues.

AJAX can be really inaccessible:

Screenreaders

Not just screenreaders

Well-written Javascript goes a long way to make things easier

Page 63: Ruby on Rails from the other side of the tracks

“Hijax”Write without Javascript

Then progressively add it, focusing on ids and classnames to act as hooks

Best of both worlds

Yes, this doesn’t work for some apps - but Web 2.0 doesn’t need to mean “inaccessible” all the time.

Page 64: Ruby on Rails from the other side of the tracks

What’s Rails doing about this?

Page 65: Ruby on Rails from the other side of the tracks

I asked DHH...

Page 66: Ruby on Rails from the other side of the tracks

“Fuck off”

Page 67: Ruby on Rails from the other side of the tracks

For everyone reading these slides who wasn’t at the

talk: DHH didn’t say this. It’s a joke.

Page 68: Ruby on Rails from the other side of the tracks

however...

Page 69: Ruby on Rails from the other side of the tracks

Luke Redpath and Dan Webb rule!

Page 70: Ruby on Rails from the other side of the tracks

Accessible Javascript Plugin:http://tinyurl.com/znzmc

Page 71: Ruby on Rails from the other side of the tracks

It’s awesome

Page 72: Ruby on Rails from the other side of the tracks

Accessible Javascript Plugin

Minimal changes to your code

No inline reference to Javascript!

Dynamically generated .js

Dynamically generated event handling

...and more

seriously impressive.

Page 73: Ruby on Rails from the other side of the tracks

Testing

Page 74: Ruby on Rails from the other side of the tracks

Everybody loves test-driven

development, right?

Page 75: Ruby on Rails from the other side of the tracks

Testing XHTMLEasy: W3C validator

Valid code is easier to debug

if it breaks, it’ll break in a consistent manner

no point writing invalid XHTML

Want to automate that?

Page 76: Ruby on Rails from the other side of the tracks

assert_valid_markup

def assert_valid_markup([email protected]) require 'net/http' response = Net::HTTP.start('validator.w3.org') do |w3c| query = 'fragment=' + CGI.escape(markup) + '&output=xml' w3c.post2('/check', query) end assert_equal 'Valid', response['x-w3c-validator-status']end

Page 77: Ruby on Rails from the other side of the tracks

No excuse for developers breaking front-end code any

more!

Page 78: Ruby on Rails from the other side of the tracks

Going furtherTest components of your page with something like Hpricot

Counting elements: boring

Checking <title> is what it should be: useful

Selenium, Watir

Beyond my scope, but certainly also useful

Page 79: Ruby on Rails from the other side of the tracks

To summarise

Page 80: Ruby on Rails from the other side of the tracks

XHTML/CSS/JSare core

components of your app, like it or not

Page 81: Ruby on Rails from the other side of the tracks

Designers and client-side developers

know their stuff, so use them!

Page 82: Ruby on Rails from the other side of the tracks

Take accessibility seriously

Page 83: Ruby on Rails from the other side of the tracks

Take validation seriously

Page 84: Ruby on Rails from the other side of the tracks

Treat your front-end folks, and their

code, as first-class citizens. The web is,

after all, only XHTML.

Page 85: Ruby on Rails from the other side of the tracks

Thanks!Recommended reading:

Designing With Web Standards - Jeffrey Zeldman

Web Standards Solutions - Dan Cederholm

CSS Mastery - Andy Budd

DOM Scripting - Jeremy Keith

The Rhino (O’Reilly js book)