如何在 Rails 中编写助手

发布于 2024-12-21 03:31:37 字数 334 浏览 1 评论 0原文

我需要检查用户收藏夹列表中的当前帖子是否

类似于(在视图中):

if in_favorites?
  #remove link
else
  #add link

Where I must place helper's code in application_controller.rb, current_controller#current_def, current_controller#custom_def 或在 application_helper.rb

I need to check is the current post in users favorites list

something like(in view):

if in_favorites?
  #remove link
else
  #add link

Where I must place helper's code in application_controller.rb, current_controller#current_def, current_controller#custom_def or in application_helper.rb

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

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

发布评论

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

评论(1

半﹌身腐败 2024-12-28 03:31:38

由于此代码将处理帖子,因此您应该将其放入 app/helpers/posts_helper.rb

Since this code would deal with posts, you should put it in app/helpers/posts_helper.rb

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