By default helpers in rails 3 generates HTML5 code, is there a way to make them output htm4 code
So that the code in rails 2.X are compatible. I want to do something that would enable me to switch between html4 and html5
Currently most of the user are using browser version which are not html5 compatible, insuch case rails should generate html4 code. In future people may use html5 compatible browsers.
currently I am using rails 3, for
<%= link_to 'delete', user, :method => 'delete'%开发者_开发技巧>
this generates
<-a rel="nofollow" data-method="delete" data-confirm="Are you sure?" href="/users/1">Destroy< - a>
This is does not work on IE7 and lower version, however works fine on IE8+
You may in fact be right about <article>
tags being interpreted as <div>
tags in HTML4 doc types. However, I think the problem presented here is that Rails 3 drops the (ugly) in line JS that ensured the request would be sent using the DELETE HTTP method. The JS is now handled unobtrusively and NOT inline. See http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/.
I am all for the idea of doing this, after all its opinionated software.
Is there a specific reason you need to switch between HTML4 and HTML5? It's my understanding that HTML5 specific tags such as <article>
will simply be treated as <div>
tags by browsers if you specify the page as HTML4.
EDIT: Seeing as th question has changed from when I originally answered it -- Try using a button for the deletion. You want to never use a link for something that will be posting/putting/ or deleting. The reason Rails uses that convention now is to provide unobtrusive javascript - so that you can interchange frameworks such as Prototype, Jquery, MooTools, etc. So there's three recommendations:
- Use a button for the delete and style it
- Go to a previous version of Rails
- Write your own helpers
- Write your own javascript to handle the delete
Rails provides helpers to create html5 tags like email_tag, number_tag etc. The best way to keep your html compatible to html4 version , we should either avoid using this new helpers or override them to render html4 code.
The issue if you use these new tags is in html5 supportive browsers you would see the different behaviour than in the one that does not support them. So its better you don't use these tag, unless most of the browsers start supporting html5 completely
精彩评论