app/helpers/app_helper.rb
class Main
module Helpers
module AppHelper
def html_escape(s)
s.to_s.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<")
end
alias h html_escape
def input(type, name, value = nil, options = {})
label = options[:label] || name.titlecase
html_id = options[:id] || name
<<-HTML
<label for="#{html_id}">#{label}</label>
<input type="#{type.to_s}" id="#{html_id}" name="#{name}" value="#{h(value.to_s)}" />
HTML
end
def text_area(name, value = nil, options = {})
label = options[:label] || name.titlecase
html_id = options[:id] || name
<<-HTML
<label for="#{html_id}">#{label}</label>
<textarea name="#{name}" id="#{html_id}">#{h(value.to_s)}</textarea>
HTML
end
end
end
end