What is the reason that the authenticity_token hidden field gets wrapped in a DIV?


#1

Hi all -

This has never been an issue for me until today. However I have a
form and Rails is inserting it’s hidden authenticity_token field. It
wraps it in a div with a style. And doing that messes things up for
me CSS wise.

Which got me to thinking about why it’s wrapped at all? Hidden fields
don’t take up any room. Why wrap it in a div which can have some side
affects? And if we’re going to wrap it, why not at least give it a
class so we can target it and set display:none which fixes the problem.

Can anyone shed some light on why this is the case? If there’s no
good reason it seems like the wrapped div should go away shouldn’t it?

-philip


#2

Following up. Looks like I’m not the only one who doesn’t like this…

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2044


#3

Can anyone shed some light on why this is the case? Â If there’s no
good reason it seems like the wrapped div should go away shouldn’t it?

Â
 Â

According to (X)HTML specification you cannot have inline elements
inside form, so inputs
must be wrapped in something: fieldset, p or div.

Regards,
Rimantas

http://rimantas.com/


#4

According to (X)HTML specification you cannot have inline elements
inside form, so inputs
must be wrapped in something: fieldset, p or div.

Ah, that would explain it then! Thanks. To anyone else who has
issues with this and CSS, check out the below patch. It works great
on 2.3.2. Basically I can override the style and set it to
display:none or display:inline…

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2044