Ramaze 的 Haml 引擎每次都返回相同的模板

发布于 2024-08-17 18:39:17 字数 415 浏览 3 评论 0原文

我的非常简单的 Ramaze 项目遇到了问题。我的项目与从“ramaz create mywebsite”生成的原型项目相同,只是我使用 Haml 模板(我在controller/init.rb 中设置了“engine :Haml”)。

以下是重现该问题的步骤:

  1. 启动开发服务器。我正在使用薄。
  2. 访问应用程序中的一项操作。到目前为止,我有“/”、“/about”和“/signup”。操作的模板将正确呈现。
  3. 参观不同的行动。这次将返回与第一个操作呈现的完全相同的内容。

只有启动开发服务器后的第一个请求才会正确呈现。

我只认为这与 Haml 有关,因为在切换回 Ramaze 的默认引擎后,一切都按预期运行。我所有的宝石都是最新的。

有什么想法吗?

谢谢你!

I've run into a problem with my very simple Ramaze project. My project is identical to the prototype project that is generated from 'ramaze create mywebsite', except that I'm using Haml templates (I set 'engine :Haml' in controller/init.rb).

Here are the steps to reproduce the problem:

  1. Start the development server. I'm using Thin.
  2. Visit one of the actions in the app. So far I have '/', '/about', and '/signup'. The template for the action will be rendered correctly.
  3. Visit a different action. This time the exact same thing which was rendered for the first action will be returned.

Only the first request after starting the dev server will be rendered correctly.

I only think it has something to do with Haml because after switching back to the default engine for Ramaze, everything works as it should. All of my gems are up to date.

Any ideas?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

陪你搞怪i 2024-08-24 18:39:17

通过恢复 Ramaze 处理 Haml 视图方式的一些假定改进来修复此问题。即使 @content 变量发生变化,它也会缓存布局的结果。
我还添加了一个规范,这样将来就不会发生这种情况: spec/ramaze/view/haml .rb

Fixed it by reverting some supposed improvements to the way Ramaze handles Haml views. It would cache the result of the layout even though the @content variable changed.
I also added a spec so this can't happen in the future: spec/ramaze/view/haml.rb

浮萍、无处依 2024-08-24 18:39:17

您可以尝试将 haml.rb 恢复到在 Ramaze 上提交 45db6fe0696dfac7deeebba42c62c6bcca8bab10 之前的状态吗?这修复了我的应用程序上的错误。

我假设该错误是由此引起的:

New haml.rb 导致该错误:

haml = View.compile(string) do |s|
  ::Haml::Engine.new(s,options).render_proc(action.instance,*action.variables.keys)
end

render_proc 的返回值被缓存。 AFAIK 使用的密钥是未处理的布局 Haml 的校验和。问题是 render_proc 在此处绑定到存储 @content 的 action.instance。

这意味着每次我们使用相同的布局(因此使用相同的缓存键)渲染页面时,我们都会使用与渲染第一个页面时使用的相同的 action.instance 。结果是我们总是得到充满相同实例变量的相同布局。

我认为制作该补丁的人假设人们在布局中使用局部变量(content)而不是实例变量(@content)。事实上,如果在布局中使用 content 而不是 @content,该错误似乎就会消失。

Can you try reverting haml.rb to the state it was before commit 45db6fe0696dfac7deeebba42c62c6bcca8bab10 on your Ramaze? That fixed the bug on my app.

I assume the bug is caused by this:

New haml.rb causing the bug:

haml = View.compile(string) do |s|
  ::Haml::Engine.new(s,options).render_proc(action.instance,*action.variables.keys)
end

The return value of render_proc is cached. The key used is, AFAIK, the checksum of the unprocessed layout Haml. The problem is that render_proc binds here to action.instance where @content is stored.

This means that every time we are rendering a page using the same layout (and thus the same cache key), we are using the same action.instance we used when rendering the first page. The result is that we always get the same layout filled with the same instance variables.

I think the person who did that patch assumed that people used local variables (content) in their layout instead of instance variables (@content). Indeed, if content is used instead of @content in the layout, the bug seems to disappear.

你的呼吸 2024-08-24 18:39:17

想出了一个解决办法!该问题与 Innate::View 缓存系统有关。通过禁用视图缓存:

Innate::View.options.cache = false

问题得到解决。显然这并不理想,但我暂时不想缓存视图并使用 Haml。我花了一些时间试图找出 Innate::View 中的问题,但我没有找到任何东西。

Figured out a workaround! The problem is involved with the Innate::View caching system. By disabling view caching:

Innate::View.options.cache = false

the problem is fixed. Obviously this isn't ideal, but I'd rather not cache views and use Haml for the time being. I spent some time trying to figure out what was wrong in Innate::View but I didn't find anything.

檐上三寸雪 2024-08-24 18:39:17

这个错误是一周前在 #ramaz 频道中报告的……似乎充耳不闻,因为它还没有得到修复。

That bug was reported in #ramaze channel a week ago.. to deaf ears it seems since it hasn't been fixed yet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文