deepwell
deepwell

Reputation: 20861

Configure Rails to output HTML output instead of XHTML

How do I configure Ruby on Rails to output standard HTML code instead of XHTML when using helpers (form, javascript, css, etc.)?

I don't want to have the slash at the end:

<input name="email" type="text" />

Upvotes: 9

Views: 1046

Answers (4)

Justin Tanner
Justin Tanner

Reputation: 14352

For rails 2.3:

Install the gem haml then add the following initializer config/initializers/force_html4.rb:

Haml::Template::options[:format] = :html4

module StandardistaHelper
  def tag(name, options = nil, open = false, escape = true)
    "<#{name}#{tag_options(options, escape) if options}>"
  end
end

ActionView::Base.send :include, StandardistaHelper

ActionView::Helpers::InstanceTag.class_eval do
  def tag_without_error_wrapping(name, options = nil, open = false, escape = true)
    "<#{name}#{tag_options(options, escape) if options}>"
  end
end

Upvotes: 0

Seth Ladd
Seth Ladd

Reputation: 120519

The solution does not work with the latest version of Rails. Some helpers will override the open method argument of 'open' to 'false'.

The following works for me in Rails 2.3.5:

module ActionView::Helpers::TagHelper
  def tag_with_html_patch(name, options = nil, open = true, escape = true)
    tag_without_html_patch(name, options, true, escape)
  end
  alias_method_chain :tag, :html_patch
end

Put that into an initializer.

Upvotes: 2

Kyle Boon
Kyle Boon

Reputation: 5231

This answer is contained in the link provided by MarkusQ, but I figured I could spell it out exactly.

You have to modify the code than renders all tags, you can do that by including the following code into something like lib/dont_use_xhtml.rb

module ActionView::Helpers::TagHelper
  alias :tag_without_backslash :tag
     def tag(name, options = nil, open = true, escape = true)
        tag_without_backslash(name, options, open, escape)
     end 
  end 

Upvotes: 6

MarkusQ
MarkusQ

Reputation: 21950

See http://railsforum.com/viewtopic.php?id=21941

-- MarkusQ

Upvotes: 1

Related Questions