在局部文件中本地定义的变量对于调用的 erb 模板是否也可见?

发布于 2024-07-27 04:15:41 字数 59 浏览 2 评论 0原文

如果我在局部变量中声明局部变量,然后从另一个 erb 模板渲染局部变量,后者是否也可以访问这些局部变量?

If I declare local variables in a partial and then render the partial from another erb template, will the latter also have accces to those local variables?

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

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

发布评论

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

评论(2

つ低調成傷 2024-08-03 04:15:41

我同意布莱恩的建议,尽管我也会推荐您参考 这个答案对于在哪里定义视图相关变量的同一主题更加全面。

I agree with Bryan's advice although I would also refer you to this answer which is a little bit more comprehensive on the same subject of where to define view-related variables.

伪心 2024-08-03 04:15:41

简短回答:是的。 理论上您将能够访问定义的变量。

更长的答案:不要在视图中定义变量。 向视图添加逻辑(从而将其推送给客户端)确实是很糟糕的做法。 使用业务逻辑模型和操作处理控制器。

Short answer: Yes. You would theoretically be able to access the defined variable.

Longer answer: Don't define variables in views. Adding logic to the views (and therefore pushing it to the client) is really bad practice. Use models for your business logic and controllers for your action handling.

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