ruby - Using rails methods with Haml::Engine -


i want have rake task reads haml file , creates static html file out of it. reason want dynamically localize error pages in manner described here http://devcorner.mynewsdesk.com/2010/01/13/rails-i18n-and-404500-error-pages/

here method writing error pages.

def write_error_page(status, locale = nil)   dest_filename = [status.to_s, locale, "html"].compact.join(".")   file.open(file.join(rails.root, "public", dest_filename), "w") |file|     path = file.join(rails.root, "app", "views", "errors", "#{status}.haml")     file.print haml::engine.new(file.read(path)).render   end    end 

the problem haml::engine not have rails methods available. when try read haml file, error every rails method in file (i want use methods image_tag, form_for , i18n.translate).

i noticed similar issue had been solved here: rails haml engine rendering

however, when try solution mentioned in link above, following error: "undefined local variable or method `config' #".

how rails methods work in haml::engine read haml file? tried switching erb, noticed leads same problem, else has @ least partially resolved here render erb database view problem please help! solution didn't me either.

i'm open other solutions using haml::engine. looked capture_haml helper don't see how me either.

you need make :environment dependency of rake task:

task :some_task => :environment   # stuff here end 

this load rails. sounds it's not been loaded.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -