Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing rails methods with Haml::Engine
    primarykey
    data
    text
    <p>I want to have a rake task that reads a HAML file and creates a static html file out of it. The reason for this is that I want to dynamically localize my error pages in a manner described here <a href="http://devcorner.mynewsdesk.com/2010/01/13/rails-i18n-and-404500-error-pages/" rel="nofollow noreferrer">http://devcorner.mynewsdesk.com/2010/01/13/rails-i18n-and-404500-error-pages/</a></p> <p>Here is the method for writing the error pages.</p> <pre><code>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") do |file| path = File.join(Rails.root, "app", "views", "errors", "#{status}.haml") file.print Haml::Engine.new(File.read(path)).render end end </code></pre> <p>The problem is that Haml::Engine does not have rails methods available. So when a try to read the haml file, I get an error for every rails method in the file (I want to use methods like image_tag, form_for and obviously I18n.translate).</p> <p>I noticed a similar issue that had been solved here: <a href="https://stackoverflow.com/questions/4097642/rails-haml-engine-rendering">Rails HAML engine rendering</a></p> <p>However, when I try the solution mentioned in the link above, I get the following error: "undefined local variable or method `config' for #".</p> <p>How could I get the rails methods to work in the Haml::Engine so that I could read the HAML file? I also tried switching to ERB, but noticed that it leads to the same problem, which somebody else has at least partially resolved here <a href="https://stackoverflow.com/questions/3922469/render-erb-from-database-into-view-problem-please-help">render erb from database into view problem please help!</a> But this solution didn't help me either.</p> <p>I'm also open to other solutions than using Haml::Engine. I looked into capture_haml helper but don't see how that would help me either.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload