English 中文(简体)
用Haml的铁路方法:
原标题:Using rails methods with Haml::Engine

我想承担一项 r忙的任务,它读写了《哈马法》档案,并立出一份静态的html档案。 其原因是,我要以下文所述的方式,动态地将我的错误网页定位为::http://isser.mynewsdesk.com/ 201001/13/rails-i18n-and-404-ror-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") do |file|
    path = File.join(Rails.root, "app", "views", "errors", "#{status}.haml")
    file.print Haml::Engine.new(File.read(path)).render
  end   
end

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).

我注意到在座已经解决的一个类似问题:。 铁路HaML发动机使

然而,当我尝试上述联系中提到的解决办法时,我发现以下错误:“没有界定地方变量或`组合'方法”。

我如何能够在Haml:Engine中找到铁路方法,以便我阅读《哈马法》档案? 我也试图转而到欧洲难民局,但注意到,这导致了同样的问题,有些人在以下网址至少部分解决了这一问题: 从数据库中发现问题,请帮助! 但这一解决办法也无助于我。

除使用Haml:Engine外,我也愿意接受其他解决办法。 我看看看看谁会帮助我。

最佳回答
问题回答

页: 1 a 依赖你的繁重工作:

task :some_task => :environment do
  # stuff here
end

这将装载铁路。 它像没有装满。

我是在你为我工作时,由于我的看法途径,我这样做的,因为我需要从我的申请助手中包含一些职能。 我认为,你可以解决问题的形式,包括:ActionView:Base.send :include, ActionView:Helpers:FormHelper

我将格式改为html,因为这是我所需要的。

def to_html
  ActionView::Base.send :include, ActionView::Helpers::ApplicationHelper

  File.open(File.join(Rails.root, "public",  test.html ), "w") do |file|

  file.print ActionView::Base.new(Rails.configuration.paths["app/views"].first).render(
                :partial =>  partial_folder/partial , 
                :format => :html,
                :locals => { :model => self}
              )
  end  
end




相关问题
How does gettext handle dynamic content?

In php (or maybe gettext in general), what does gettext do when it sees a variable to dynamic content? I have 2 cases in mind. 1) Let s say I have <?=$user1?> poked John <?=$user2?>. ...

Explain the Need for Mutexes in Locales, Please

Reading the question Why doesn’t C++ STL support atoi(const string& ) like functions?, I encountered a comment which warned that GCC (at least) has a bug that can slow down multi-threaded ...

How does Vistalizer work

How does Vistalizer manage to override the language limit in Windows Vista Home edition. Which api s does it use to allow installation of Multiple language packages.

Localized exceptions (within a Struts2 app)

I am developing a Struts 2 application with support for multiple languages. If one of the domain objects needs to throw an exception, how can it do so in such a way that the error message is no ...

Rails Globalize plugin help

Has anyone gotten the Globalize plugin to work Rails 2.3.2 or later? If so, could you direct me to some useful info?

热门标签