# Rails Cookbook review

**URL:** <https://www.ruby-forum.com/t/rails-cookbook-review/144237>\
**Category:** Rails\
**Created:** [July 27, 2008, 7:27am UTC](https://www.ruby-forum.com/t/rails-cookbook-review/144237 "2008-07-27T07:27:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [July 27, 2008, 7:27am UTC](https://www.ruby-forum.com/t/rails-cookbook-review/144237/1 "2008-07-27T07:27:02Z")

</div>

Guys:

Stuck at the mall today, and just had to crack Rails Cookbook, by  
O’Reilly. It  
had a recipe for accepting dynamically created forms. The recipe  
resolved to  
build a grid on a page, and submit it with enumerable form post names.

The sample output looked like this (reconstructed):

p params[:my\_form]

> [“1-1” =\> 0, “1-2” =\> 0, “1-3” =\> 0, “2-1” =\> 0, “2-2” =\> 0,  
> “2-3” =\> 0, “3-1” =\> 0, “3-2” =\> 0, “3-3” =\> 0]

Does anyone have the book to hand? The technical problem here is…

A\> naming a form field different from its ID is bad luck  
B\> an HTML ID should not start with a numeral (right?)

Can someone check if the book permits this bug in the IDs? Ruby form  
helpers  
make it kind’a easy…

–  
Phlip

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [July 27, 2008, 3:50pm UTC](https://www.ruby-forum.com/t/rails-cookbook-review/144237/2 "2008-07-27T15:50:52Z")

</div>

On Sat, Jul 26, 2008 at 10:12:21PM -0700, Phlip wrote:

> ```
> "2-3" => 0, "3-1" => 0, "3-2" => 0, "3-3" => 0]
> 
> ```
> 
> Does anyone have the book to hand? The technical problem here is…
> 
> A\> naming a form field different from its ID is bad luck

Where do you get this from? There’s nothing wrong with naming a form  
field  
something other than it’s ID, or not giving it an ID at all.

> B\> an HTML ID should not start with a numeral (right?)

I’d have to check the HTML/XML spec, but that sounds right. Anyway, the  
simplest solution is to use the name prefixed with something (e.g.  
dynamic\_) as the ID. Mind you, I suspect most browsers will happily deal  
with whatever string you put in the ID field, numeric or not.

> Can someone check if the book permits this bug in the IDs? Ruby form  
> helpers make it kind’a easy…

I don’t even know what you’re asking here.

> Phlip  
> –Greg

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [July 27, 2008, 5:35pm UTC](https://www.ruby-forum.com/t/rails-cookbook-review/144237/3 "2008-07-27T17:35:42Z")

</div>

Gregory S. wrote:

> > A\> naming a form field different from its ID is bad luck
> 
> Where do you get this from? There’s nothing wrong with naming a form field  
> something other than it’s ID, or not giving it an ID at all.

It’s just “bad luck”. As in “superstition causes bad luck”.

> > B\> an HTML ID should not start with a numeral (right?)
> 
> I’d have to check the HTML/XML spec, but that sounds right.

I suspect some validators catch it, too.

> I don’t even know what you’re asking here.

I did not buy the book. If anyone has it, can they check the source and  
see if a  
published Rails book lead users to create invalid IDs?

Ruby helpers, such as check\_box\_tag, tend to clone 'name’s to produce  
'id’s. So  
that’s one way Rails could accidentally generate invalid IDs…

–  
Phlip
