【问题标题】:is there a way to bind variables to an html file in the public/ directory in rails有没有办法将变量绑定到rails中public/目录中的html文件
【发布时间】:2012-01-03 09:10:35
【问题描述】:

我有以下文件:

#{RAILS_ROOT}/public/mytemplate/index.html

在一个带有某些类似模板的变量的 html 文件中,如下所示:

<div class="hover">
  <h1 id="user_name">{user_name}</h1>
</div>

<h2 id="project_name">{project_name}</h2>

从一个控制器动作,我需要渲染这个文件,我正在使用它

render :file => "#{RAILS_ROOT}/public/mytemplate/index.html"

但我想将变量映射到模板值。例如,我想指定 @project.name 映射到 project_name。如何指定此映射?

【问题讨论】:

    标签: templates jquery-templates ruby-on-rails-2


    【解决方案1】:

    在控制器动作中,添加以下代码: project_name = @project.name 我想这就是你想要的,对吧?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-14
      • 2014-11-07
      • 1970-01-01
      相关资源
      最近更新 更多