启用turbo_frame:有条件的模态标签

发布于 2025-01-31 07:46:55 字数 685 浏览 2 评论 0原文

我有一个用于创建新项目的链接

  <li>
    <%= link_to "List an item", new_item_path, data: { turbo_frame: 'modal' } %>
  </li>

,此链接在turbo_frame_tag modal &lt;%= turbo_frame_tag“ modal”%&gt;

我需要做的是允许用户仅列出3个项目。如果他们单击上面,则将其重定向到root_path,并带有通知。

我在项目控制器中有这样的验证:

before_action :check_limited_items, if: :signed_in?, only: :new

  def check_limited_items
    limited_items = 3
    return unless current_user.items_count == limited_items

    redirect_to root_path
    flash[:notice] = "Allow 3 items only."
  end

当我单击上面的链接以获取新项目时,它无济于事。当我刷新时,会出现闪电通知。

我该如何解决?控制器是验证或模型的好地方吗? 我尝试了同样的结果。

I have a link for creating a new item

  <li>
    <%= link_to "List an item", new_item_path, data: { turbo_frame: 'modal' } %>
  </li>

This opens a item form in a turbo_frame_tag modal <%= turbo_frame_tag "modal" %>

What I need to do is, allow users to list 3 items only. And if they click on above link it redirect it to root_path with a notice.

I have such validation in item controller:

before_action :check_limited_items, if: :signed_in?, only: :new

  def check_limited_items
    limited_items = 3
    return unless current_user.items_count == limited_items

    redirect_to root_path
    flash[:notice] = "Allow 3 items only."
  end

When I click on above link for a new item, it does nothing. When i refresh, flash notice shows up.

How could I fix that? And is a controller a good place for validation or model?
I tried both and same result.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文