2

I would like to use HTML 4.01 Strict, and used a DOCTYPE of it in my application template. But look like when a style sheet is included by a helper function

<%= stylesheet_link_tag 'style' %>

the code produced is XHTML:

<link href="/stylesheets/style.css?1243210734" media="screen" rel="stylesheet" type="text/css" />

is there a way to ask Rails to produce HTML instead of XHTML? (so that the HTML will validate for example)

2 Answers 2

3

Just a quick fix to the included code above, which does work.

module ActionView::Helpers::TagHelper
  def tag_with_html(name, options = nil, open = true, escape = true)
    tag_without_html(name, options, true, escape)
  end
  alias_method_chain :tag, :html
end

Thanks for the tip!

Sign up to request clarification or add additional context in comments.

Comments

0

Not really, no.

Edit: in line with my comment below, this should work (I still feel uneasy, but I can't think of anything that will break because of this)

module ActionView::Helpers::TagHelper
  def tag_with_html(name, options = nil, open, escape = true)
    tag_without_html(name, options, true, escape)
  end
  alias_method_chain :tag, :html
end 

2 Comments

there was an old post, i later found: stackoverflow.com/questions/595867/… but the solution seems a bit hacky...
The problem with these solutions, both the one in stackoverflow and the one on railsforum is that they're just providing a default value for the open argument. Plenty of Rails helpers explicitly set this to false, so the default will have no effect. Come to think of it though, in HTML there's NEVER a need to have a self-closing tag. So actually the examples should work if you actually just override the close parameter to ALWAYS be false.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.