Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Rails Task To Find Code Typos In Rhtml Templates

DZone's Guide to

Rails Task To Find Code Typos In Rhtml Templates

·
Free Resource

namespace :typos do 
  task :rhtml do
    require 'erb'
    require 'active_support'
    require 'action_view'

    module TempTemplates; end
    Dir["./app/views/**/*.rhtml"].each do |fname|
      local_source = ERB.new(IO.read(fname), nil, '-').src
      template_source = "def _tmpl\n#{local_source}\nend"
      begin
        TempTemplates.module_eval(template_source, fname, 0 )
      rescue Object => e
        t = ActionView::TemplateError.new("./app/views/", fname, {}, template_source, e)
        puts "TemplateError (#{t.message}) on line ##{t.line_number} of #{t.file_name}:\n"+t.source_extract + "\n------\n"
      end
    end
  end
end

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}